New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


how to use %host in powershell ?

Votes:

0

Your Vote:

Up

Down

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 by  LoisP (0) 1



3 Replies

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  LoisP (0) 1



Votes:

0

Your Vote:

Up

Down

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]



Please log in or register to enter your reply.


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.