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.
Add comment