What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

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.

Free Download

Top Tags


View all Tags

Custom Sensor EXE/Script Advanced cannot load PowerShell Module

Votes:

0

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)

custom-sensor prtg script

Created on Mar 17, 2022 9:40:07 AM

Last change on Mar 17, 2022 1:16:42 PM by  Felix Wiesneth [Paessler Support]



5 Replies

Votes:

0

Hey,

Did you use the Powershellx86 or x64 for executing the script manually with the needed credentials?

Created on Mar 22, 2022 12:06:25 PM by  Marijan Horsky [Paessler Support]



Votes:

0

We already tried both but it still does not work.

Created on Mar 23, 2022 7:18:06 AM



Votes:

0

Hi I found the Solution: The Module "Universal Print Management" can only be loaded from a 64-Bit PowerShell session. We needed to start the Script with a 64-Bit PowerShell as in this thread discribed (https://kb.paessler.com/en/topic/32033-is-it-possible-to-use-the-64bit-version-of-powershell-with-prtg)

Created on Mar 24, 2022 6:19:41 AM



Votes:

0

Hey,

Does this script also work in PRTG directly after the change?

Created on Mar 25, 2022 8:07:30 AM by  Marijan Horsky [Paessler Support]



Votes:

0

It worked directly after we applied the change. We instantly got a correct read in PRTG.

Created on Mar 25, 2022 8:18:41 AM




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.