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

how to use %host in powershell ?

Votes:

0

hi everyone

I'm new in powershell and prtg.

I want to use the parameter %host for my powershell but I don't see how to use it ?

{{{param( [string]$host="defaulthost" )

$trace = Invoke-Command -ComputerName $host -ScriptBlock {

qfarm /load $host

}

$a=$trace[3] $b=$a.Substring(22) $c=$b.Trim() $d=[int]$c

Write-Host "<prtg>" Write-Host "<result>" Write-Host "<channel>Charge</channel>" Write-Host "<float>1</float>" Write-Host "<value>$d</value>" Write-Host "</result>" Write-Host "</prtg>"}}}

custom-sensor powershell script

Created on Oct 31, 2018 4:11:35 PM



3 Replies

Votes:

0

Dear LoisP,

in order to use the placeholder %host, please put it into the sensor setting "Parameters". When PRTG start the executable script, it provides the input of this field, but resolves the placeholders first.

Created on Oct 31, 2018 5:14:34 PM by  Arne Seifert [Paessler Support]



Votes:

0

Thx for the reply. That what I done but in the log I have.

Impossible de remplacer la variable host, car elle est constante ou en lecture seule. Au caractŠre Ligne:1 : 137 + if ($PSVersionTable.PSVersion.Major -ge 5) { Import-Module Microsoft.PowerShell. ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : WriteError: (host:String) [], SessionStateUnauth orizedAccessException + FullyQualifiedErrorId : VariableNotWritable

In my code Powershell, did I put it right ?

Created on Oct 31, 2018 6:04:52 PM



Votes:

0

Dear LoisP,

checking custom Powershell scripts is not part of our support, I am sorry.

The error message looks like you got a general error regarding the handling of variables, meaning it looks like the script tries to write to a readonly property.

The placeholder is %host, but you can name the according variable (in which you put the resolved value of %host) differently, in order to avoid naming conflicts.

If you experience issues with getting parameters into the script, you can use the sensor option "Set placeholders as environment values". You can then read the placeholders you put into the sensor parameter field from the virtual drive Env: using get-childitem.

Created on Nov 1, 2018 2:26:26 PM by  Arne Seifert [Paessler Support]




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.