Hello,

I want to execute a Powershell script from a remote probe to another server within the same network. When I change the param $ComputerName to a valid value I get results like I should, but when I put the script in PRTG it does not show any values. Even when I specify the computername manually.

This is the script that I use:

param( [string]$ComputerName = "defaulthost" )

enter-pssession $ComputerName

$value= Get-WmiObject -Query "SELECT * FROM Win32_Processor" -ComputerName $ComputerName $LoadPercentage = $value.LoadPercentage

$value2= Get-WmiObject -Query "SELECT * FROM Win32_OperatingSystem" -ComputerName $ComputerName $FreePhysicalMemory = $value2.FreePhysicalMemory/1024

$MemoryUsed = ($value2.FreePhysicalMemory/$value2.TotalVisibleMemorySize) * 100 $PercentMemoryUsed = "{0:N2}" -f $MemoryUsed $PercentMemoryUsed = $PercentMemoryUsed -replace ("," , ".")

Write-Host "<prtg>"

Write-Host "<result>" Write-Host "<channel>Processor Percentage</channel>" Write-Host "<value>$LoadPercentage</value>" Write-Host "<float>1</float>" Write-Host "<showTable>1</showTable>" Write-Host "<showChart>1</showChart>" Write-Host "<unit>Go</unit>" Write-Host "<mode>Absolute</mode>" Write-Host "<warning>0</warning>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Beschikbaar Geheugen MB</channel>" Write-Host "<value>$FreePhysicalMemory</value>" Write-Host "<float>1</float>" Write-Host "<showTable>1</showTable>" Write-Host "<showChart>1</showChart>" Write-Host "<unit>Go</unit>" Write-Host "<mode>Absolute</mode>" Write-Host "<warning>0</warning>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Beschikbaar Geheugen %</channel>" Write-Host "<value>$PercentMemoryUsed</value>" Write-Host "<float>1</float>" Write-Host "<showTable>1</showTable>" Write-Host "<showChart>1</showChart>" Write-Host "<unit>Go</unit>" Write-Host "<mode>Absolute</mode>" Write-Host "<warning>0</warning>" Write-Host "</result>"

Write-Host "</prtg>"

exit-pssession

Or is there another way to use remote Powershell and PRTG?

Thanks in advance!


Article Comments

Hello Ferron,

Which version of PRTG are you running at the moment? Please do also forward the output of the script for further investigation.

Best regards, Felix


Apr, 2016 - Permalink