New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

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!

Learn more

 

Top Tags


View all Tags


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

Votes:

0

Your Vote:

Up

Down

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.

powershell prtg script

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  Stephan Linke [Paessler Support]



3 Replies

Votes:

0

Your Vote:

Up

Down

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

www.it-admins.com

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



Votes:

0

Your Vote:

Up

Down

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)



Votes:

0

Your Vote:

Up

Down

Could you try the following code instead:

Write-host "Disable Certificate checks"
Add-Type @"
    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  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.