I'm trying to use a powershell Script in a Notification, but I can't get it to work correctly with parameters, that are Placeholders.

The Script I'm trying to run just writes a file containing the parameters and some other info.

I tried with standard parameters: "%sitename %device %name %status %down %message" -> I get no file at all, but as soon as I remove the %sitename, I get a file, but the other parameters aren't resolved, just passed as string %device, %name etc. (In the Notification Test) - which is normal I suppose, since there is no device that sent the event.

When I test this with a real device though ( I set the new Notification on a Ping sensor and then killed the Network Connection) I get no file again.

This is the Script:

param(
    [string]$SiteName = "N/A",
    [string]$Device = "N/A",
    [string]$Name = "N/A",
    [string]$Status = "N/A", 
    [string]$Down = "N/A",
    [string]$Message = "N/A"
    )


$numbers = @(0000)
$outpath = "\\server\sms\outgoing\"
foreach ($number in $numbers){
    $date = Get-Date
    $outfile = $outpath + $date.ToString("hhmmssfff")
    $outstr = "To: $number" + [System.Environment]::NewLine + [System.Environment]::NewLine

    $outstr= $outstr +"$SiteName $Device $Name $Status $Down $Message"
    $outstr | Out-File -FilePath $outfile -Encoding ascii
}

exit 0


Article Comments

Hello,

thank you very much for your KB-Post. May I ask, how exactly do you pass on the parameters then in PRTG? Can you please try encapsulating them individually with either " or ' ?
Does this help?

best regards.


May, 2014 - Permalink

My script is still having trouble, even after passing parameters like this:

   '%hostname' '%linuxuser' 'linuxpassword'

and like this:

   "%hostname" "%linuxuser" "%linuxpassword"

It completes the task if I hard-code the values, but I can't seem to get the parameters passed correctly from PRTG.

Script:

param(
    [string]$hostName= "N/A",
    [string]$lxuser= "N/A",
    [string]$lxpasswd= "N/A",
    )
$creds = New-Object System.Management.Automation.PSCredential($lxuser,$lxpasswd)

New-SSHSession -ComputerName $hostName -Credentials $creds -AcceptKey $TRUE
Invoke-SSHCommand -Index 0 -Command "service apache2 start"
Remove-SSHSession -Index 0


Oct, 2015 - Permalink

Please be aware that we can only provide very limited support with custom scripting. We recommend to build logging output into your script, so that it writes log entries with each step. This should help to identify the cause. It may be an account issue here if it runs fine under your account on CMD, but not with the "LOCAL SYSTEM"-account of the Probe Service.


Oct, 2015 - Permalink