Hi there,
we got a Problem with a Custom Sensor. We developed a Script for reading out the Remaining Print Jobs for the Azure Universal Print Service. The Script works perfectly fine when being executed manually on the Probe with the Service User that is needed. We configured PRTG to execute the Script with the Service User's Credentials. If we try to execute the Script via PRTG we always get this Error Message:
Could not load file or assembly 'file:/C:\ProgramFiles\WindowsPowerShell\Modules\UniversalPrintManagement\1.0.1\Microsoft.UniversalPrintManagement.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Is there any fix for this behavior?
The Script Looks like the following:
$SaveCredentials = $true $ZielServer = "Server.domain" if ($SaveCredentials) { $CredentialXML ="C:\Users\ServiceUser\AppData\Local\Credentials-$($ZielServer).xml" Write-Verbose "Authentification: Using $CredentialXML as Storage. Delete file if you get authentification errors." -Verbose # Generate Credentials, if not available. if (!(Test-Path $CredentialXML)) { $UserCredential = Get-Credential -Message "Please Login with your Credentials" $UserCredential | Export-Clixml -Path $CredentialXML } # Load Credentials $UserCredential = Import-Clixml -Path $CredentialXML } else { $UserCredential = Get-Credential -Message "Please Login with your Credentials" } # create temporary console ping localhost -n 1 | Out-Null # set output encoding [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $date =(Get-Date).ToString("[yyyy/MM/dd]") $Logfile = "C:\UP_Report\UniversalPrint.log" function WriteLog { Param ([string]$LogString) $Stamp = (Get-Date).toString("[yyyy/MM/dd HH:mm:ss]") $LogMessage = "$Stamp $LogString" Add-content $LogFile -value $LogMessage } WriteLog "Script has started successfully" try{ Import-Module UniversalPrintManagement Connect-UPService -UserPrincipalName SVC_UPReporting@domain -Password $($UserCredential).Password } Catch{ WriteLog "Sign-in was unsuccessfull" WriteLog "$Error[0]" } try{ $reportlist = @() $yearmonth = Get-Date -Format yyyy-MM- for ($i = 1 ; $i -lt ((Get-Date).Day +1 ) ; $i++ ) { $current = get-date "$($yearmonth)$($i)" $reportlist += (Get-UPUsageReport -ReportType DailyPrinter -StartDate $current -EndDate $current ).Results } $summeBWandColor = [int64]"0" for ($i = 0; $i -lt $reportlist.Count ; $i++ ) { $summeBWandColor = $summeBWandColor + $reportlist[$i].CompletedBlackAndWhiteJobCount + $reportlist[$i].CompletedColorJobCount } $remainingPrintJobs = [int64]"0" $remainingPrintJobs = 12725-$summeBWandColor WriteLog "Remaining Print Jobs at $date - $remainingPrintJobs" WriteLog "Script was executed successfully" } catch{ WriteLog "Script-Execution failed" } ##################################################### Ausgabe ############################################################################################# #An PRTG senden [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $output = @" <?xml version=`"1.0`" encoding=`"UTF-8`" ?> <prtg> <result> <channel>Anzahl PrintJobs</channel> <value>$remainingPrintJobs</value> </result> <text>Es sind noch $remainingPrintJobs von 12725 Print Jobs vorhanden</text> </prtg> "@ [Console]::WriteLine($output)
Add comment