Hi,
I've created the following script:
Write-Host "<prtg>"
param([string]$ComputerName)
$value= Get-WmiObject -Query  "SELECT * FROM Win32_Processor" -ComputerName $ComputerName
		$LoadPercentage = $value.LoadPercentage
		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>"
$value2= Get-WmiObject -Query  "SELECT * FROM Win32_OperatingSystem" -ComputerName $ComputerName
		
		$FreePhysicalMemory = $value2.FreePhysicalMemory/1024
		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>"
		
	
$MemoryUsed = ($value2.FreePhysicalMemory/$value2.TotalVisibleMemorySize) * 100
$PercentMemoryUsed = "{0:N2}" -f $MemoryUsed
$PercentMemoryUsed = $PercentMemoryUsed -replace ("," , ".")
		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>"
When I manually specify the $ComputerName variable everything works fine. But I want to set the computername with the parameter field from the sensor. I've looked everywhere, but I can't find a working example.
I hope someone has an answer for me.
Article Comments
param() must be the first non-comment line in the file. Place it before Write-Host "<prtg>"
Its good practice to always test your scripts manually before calling them from PRTG
Apr, 2016 - Permalink
Two steps are required, the first is "reading" the parameter in powershell, which you are already doing:
param( [string]$host = "defaulthost" ) (script continues...)Then, in PRTG configure the Parameters section of the sensor's settings, for instance to "pass" the IPv4 Address/DNS Name from the parent device where the sensor was deployed enter %host in the parameters field. For more details on the available parameters see the Command line Parameters from the Setup > PRTG API > Custom Sensors page.
The same process may be used to forward credentials and other parameters as well.
There's a similar example in this tutorial.
Apr, 2016 - Permalink