### What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

View all Tags

# The Powershell script works but PRTG can not execute it properly.

#### 0

Hello scripting support,

Here' my probleme :

$user = "admin" ##mdp$path = "C:\my\path\to\my\file\myHashPassowrd.txt"

$password = cat$path | convertto-securestring

$cred = New-Object System.Management.Automation.PSCredential($user, $password) ##bypass self-signed certificate Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy$WebRequest=Invoke-WebRequest -URI 'https://myWifiController.html' -Credential $cred -SessionVariable cisco$current_aps = $WebRequest.AllElements | where {$_.name -like "current_aps"} | select value

$current_down_aps =$WebRequest.AllElements | where {$_.name -like "current_down_aps"} | select value$current_up_aps = $WebRequest.AllElements | where {$_.name -like "current_up_aps"} | select value

Write-Host "<prtg>"

Write-Host "<result>"

Write-Host "<channel>Total d'AP</channel>"

Write-Host "<value>"$current_aps.value"</value>" Write-Host "</result>" Write-Host "<result>" Write-Host "<channel>AP DOWN</channel>" Write-Host "<value>"$current_down_aps.value"</value>"

Write-Host "</result>"

Write-Host "<result>"

Write-Host "<channel>AP UP</channel>"

Write-Host "<value>"$current_up_aps.value"</value>" Write-Host "</result>" Write-Host "<text>Nombre d'AP Down : "$current_down_aps.value"/"$current_aps.value"</text>" Write-Host "</prtg>"  This script works, here is the output: <prtg> <result> <channel>Total d'AP</channel> <value> 52 </value> </result> <result> <channel>AP DOWN</channel> <value> 0 </value> </result> <result> <channel>AP UP</channel> <value> 52 </value> </result> <text>Nombre d'AP Down : 0 / 52 </text> </prtg>  But, Here is the sensor log : Add-Type : (0)ÿ: Impossible de trouver le fichier source 'C:\Windows\TEMP\waip3m11.0.cs' (1)ÿ: using System.Net; Au caractŠre C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\script_CISCO_Controller_AP_status_v4.ps1:34 : 1 + Add-Type @" + ~~~~~~~~~~~ + CategoryInfo : InvalidData : (error CS2001: I...\waip3m11.0.cs':CompilerError) [Add-Type], Exception + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand Add-Type : (0)ÿ: Aucun fichier source sp‚cifi‚ (1)ÿ: using System.Net; Au caractŠre C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\script_CISCO_Controller_AP_status_v4.ps1:34 : 1 + Add-Type @" + ~~~~~~~~~~~ + CategoryInfo : InvalidData : (warning CS2008:...source sp‚cifi‚:CompilerError) [Add-Type], Exception + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand Add-Type : Impossible d'ajouter un type. Des erreurs de compilation se sont produites. Au caractŠre C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\script_CISCO_Controller_AP_status_v4.ps1:34 : 1 + Add-Type @" + ~~~~~~~~~~~ + CategoryInfo : InvalidData : (:) [Add-Type], InvalidOperationException + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand New-Object : Le type [TrustAllCertsPolicy] est introuvable: v‚rifiez que l'assembly dans lequel il se trouve est charg‚. Au caractŠre C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\script_CISCO_Controller_AP_status_v4.ps1:49 : 55 + [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand Invoke-WebRequest : La connexion sous-jacente a ‚t‚ ferm‚e: Impossible d'‚tablir une relation de confiance pour le canal s‚curis‚ SSL/TLS. Au caractŠre C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\script_CISCO_Controller_AP_status_v4.ps1:52 : 13 +$WebRequest=Invoke-WebRequest -URI 'https://myWifiController.html ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebEx
ception
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

0:   /  </text> </prtg>


So what am I doing wrong ?

Cordially.

Created on Oct 1, 2018 10:35:47 AM by John Doe (0) 1

Last change on Oct 1, 2018 6:16:13 PM by

3 Replies

#### 0

Add-Type : (0)ÿ: Impossible de trouver le fichier source 'C:\Windows\TEMP\waip3m11.0.cs' (1)ÿ: using System.Net;

translates to: Can not find the source file

This means you might have an issue with 32-bit vs. 64-bit or the script needs components on the probing server itself.

It is always a good idea to logon as the actual executing user to the PRTG server and try the script to see if there are permission issue. If this is not the case, then investigate 32bit and 64bit.

Sorry - did not translate all of your log-file output, the if there is a .cs file missing in the first place, the rest could be just related to that and is to be discarded until the first issue is resolved.

Regards

Florian Rossmark

Created on Oct 2, 2018 1:49:24 PM by Florian Rossmark (4,436) 4 2

#### 0

Hi there, I am experiencing the same issue on a Windows Server 2016 Datacenter. When run in an interactive (Admin 32 or 654bit) powershell or ISE session the same script executes successfully. When run via PRTG/PRTG Probe server receive the same error message.

Both servers have .net 4.72 installed. Both servers have are in the same Active Directory OU and have the same GPO/Security applied to them and the PRTG service account has the same rights on both servers.

The minor differences are (so far) Powershell; Old PRTG probe servers Windows 2012R2 - 5.1.14409.101 New PRTG probe server Windows 2016 -5.1.14393.2879

Is there any additional information you may require that may assist in analyzing the root cause.

Note: The script faults when the "Add-Type" verb is issued, but only when the script is run via PRTG????

Created on May 22, 2019 4:07:47 PM by Tony Mason (0)

#### 0

Could you try the following code instead:

Write-host "Disable Certificate checks"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
"@
[ServerCertificateValidationCallback]::Ignore();


...and let me know if that one works?

Created on May 23, 2019 6:25:53 AM by