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>"}}}
Article Comments
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 ?
Oct, 2018 - Permalink
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.
Nov, 2018 - Permalink
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.
Oct, 2018 - Permalink