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

Script Returns string, how to handle this in PRTG?

Votes:

0

I would like to use this script to monitor the state of Antivrus on several computers, but it returns a string and prtg can't handle a string value in the "EXE/script" sensor! Is there another way to resolve this? This is the script i am using:

param($windowdomain,$windowsuser,$windowspassword,$computername)

$secpasswd = ConvertTo-SecureString $windowspassword -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("$($windowsdomain)\$($windowsuser)", $secpasswd)

$AV = Get-WmiObject -ComputerName $computer -Credentials ($mycreds) -Namespace root\SecurityCenter2 -Class AntiVirusProduct 
switch ($AV.productState) { 
"262144" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"262160" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"266240" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"266256" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"393216" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"393232" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"393488" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"397312" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"397328" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397584" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397568" {$UpdateStatus = "Up to date"; $RealTimeProtectionStatus = "Enabled"}
"393472" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"}
default {$UpdateStatus = "Unknown" ;$RealTimeProtectionStatus = "Unknown"} 
}
Write-Host ("0:" + $AV.displayname + " - " + $UpdateStatus + " - " + $RealTimeProtectionStatus)

monitoring powershell prtg-network-monitor

Created on May 31, 2018 11:36:54 AM

Last change on May 31, 2018 12:30:17 PM by  Stephan Linke [Paessler Support]



27 Replies

Votes:

0

Use the following instead:

Write-Host ("0:" + $AV.displayname + " - " + $UpdateStatus + " - " + $RealTimeProtectionStatus)

Created on May 31, 2018 11:40:20 AM by  Stephan Linke [Paessler Support]



Votes:

0

thx Stephan, it is better but the result isn't what i expected :-), if run the script on the remote computer i get the result "up to date" on PRTG i get "Unknown" Is the script running on the probe itself?

Created on May 31, 2018 11:53:22 AM



Votes:

0

Welp - yes, indeed. You'll need to pass -Computername "%host" and -Credential $credential. To create a credential object, check out this :)


Kind regards,
Stephan Linke, Tech Support Team

Created on May 31, 2018 12:04:11 PM by  Stephan Linke [Paessler Support]



Votes:

0

Thx Stephen, where should I place this two lines in the script? At the beginning?

grtz R

Created on May 31, 2018 12:18:46 PM



Votes:

0

Something like this - I updated your first post accordingly. Use the following parameters in PRTG: "%windowsdomain" "%windowsuser" "%windowspassword" "%host"

param($windowdomain,$windowsuser,$windowspassword,$computername)

$secpasswd = ConvertTo-SecureString $windowspassword -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("$($windowsdomain)\$($windowsuser)", $secpasswd)

$AV = Get-WmiObject -ComputerName $computer -Credentials ($mycreds) -Namespace root\SecurityCenter2 -Class AntiVirusProduct 
switch ($AV.productState) { 
"262144" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"262160" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"266240" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"266256" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"393216" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"393232" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"393488" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"397312" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"397328" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397584" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397568" {$UpdateStatus = "Up to date"; $RealTimeProtectionStatus = "Enabled"}
"393472" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"}
default {$UpdateStatus = "Unknown" ;$RealTimeProtectionStatus = "Unknown"} 
}
Write-Host ("0:" + $AV.displayname + " - " + $UpdateStatus + " - " + $RealTimeProtectionStatus)

Created on May 31, 2018 12:27:46 PM by  Stephan Linke [Paessler Support]

Last change on May 31, 2018 12:29:43 PM by  Stephan Linke [Paessler Support]



Votes:

0

Thx Stephan, but where exactly should I give the computername, domain, username and password in? The parameter field on the exe/script page?

Created on May 31, 2018 12:51:33 PM



Votes:

0

Exactly there and in that order :) You'll need to configure Windows credentials in the device accordingly.

Created on May 31, 2018 12:55:48 PM by  Stephan Linke [Paessler Support]



Votes:

0

Stephen,

i don't know exactly the syntax so i wrote it like this:

$windowdomain ABCD,$windowsuser EFGH,$windowspassword IJKL,$computername 192.168.2.2

is this the correct way?

thx a lot!

Created on May 31, 2018 1:00:12 PM



Votes:

0

You'll need to enter (copy/paste) the following into the parameter field of the sensor:
"%windowsdomain" "%windowsuser" "%windowspassword" "%host"

The placeholders will be replaced by PRTG internally when executing the script :)

Created on May 31, 2018 1:03:57 PM by  Stephan Linke [Paessler Support]



Votes:

0

Stephan,

where in the script should i put my credentials in plaintext?

grtz

Created on May 31, 2018 1:36:15 PM



Votes:

0

You don't need to. As mentioned, enter the credentials in the device settings of PRTG (in the Windows credentials section). The script, when ran by PRTG, will get the corresponding values via the placeholders you entered in the parameter field. The credential object is then created at runtime and the script will log into the target host using the same.


Kind regards,
Stephan

Created on May 31, 2018 1:52:42 PM by  Stephan Linke [Paessler Support]



Votes:

0

OK I see! Thanks a lot Stephan but it doesn't give me te correct result!Value is still "unknown" and should be "up to date":-(

Created on May 31, 2018 2:10:25 PM



Votes:

0

Could you try "Use credentials of parent device" in the sensor security context setting?

Created on Jun 1, 2018 3:01:27 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan, I did but i don't see any changes :-(, maybe the output is the problem! The output should be:

COMODO Antivirus / up to date / enabled

but i get as output:

/unknown/unknown

Could the textfield format/field be the problem in PRTG?

Created on Jun 1, 2018 9:54:51 AM



Votes:

0

It probably still cannot access the target host. You may need to tinker with Remote PowerShell instead :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 1, 2018 5:27:54 PM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan,

this is the error and output i get when running the script on the remote computer:

Write-Host ("0:" + $AV.displayname + " / " + $UpdateStatus + " / " + $RealTimeProtectionStatus)
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At line:3 char:36
+ $secpasswd = ConvertTo-SecureString <<<<  $windowspassword -AsPlainText -Force
    + CategoryInfo          : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
 
New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value."
At line:4 char:22
+ $mycreds = New-Object <<<<  System.Management.Automation.PSCredential ("$($windowsdomain)\$($windowsuser)", $secpasswd)
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
 
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At line:7 char:34
+ $AV = Get-WmiObject -ComputerName <<<<  $computer -Credentials ($mycreds)-Namespace root\SecurityCenter2 -Class AntiVirusProduct 
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
0: / Unknown / Unknown

Created on Jun 4, 2018 9:00:49 AM

Last change on Jun 4, 2018 9:24:34 AM by  Stephan Linke [Paessler Support]



Votes:

0

Are you actually putting values in the parameter values? It's complaining about the password being empty...

Created on Jun 4, 2018 9:48:18 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan, you mean this parameters?

You'll need to enter (copy/paste) the following into the parameter field of the sensor: "%windowsdomain" "%windowsuser" "%windowspassword" "%host"

The placeholders will be replaced by PRTG internally when executing the script :)

I replaced those parameters in:

"ABCD" "EFGH" "IJKL" "MNOP"

is that correct?

Created on Jun 4, 2018 9:58:51 AM



Votes:

0

Stephan, I think he is complaining because i am executing the script local on the target system!

Created on Jun 4, 2018 10:02:58 AM



Votes:

0

Could you post a screenshot of the settings of the sensor, specifically the parameter field? Just want to make sure we're not talking past each other. Check the markup options on how to embed images.

Created on Jun 4, 2018 11:13:57 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan,

Printscrn Sensor parameters

Created on Jun 4, 2018 11:28:33 AM

Last change on Jun 4, 2018 11:34:43 AM by  Stephan Linke [Paessler Support]



Votes:

0

Copy this, 1:1 into the parameter field and save it:
"%windowsdomain" "%windowsuser" "%windowspassword" "%host"

The placeholders are dynamically replaced by PRTG and you don't need to enter anything except the line above.

Created on Jun 4, 2018 11:36:36 AM by  Stephan Linke [Paessler Support]



Votes:

0

Stephan, that's what i did in a previous scenario and it didn't work, that's why i used now these values! I don't use values in my script because that script will be used for other computers too! I use that parameter field for the remote hosts.

Created on Jun 4, 2018 11:47:32 AM



Votes:

0

Stephan, thx for the support! I fixed the problem! I changed my script in:

param(
    $computername = "localhost"
    )

$AV = Get-WmiObject -ComputerName $computername -Namespace root\SecurityCenter2 -Class AntiVirusProduct 
switch ($AV.productState) { 
"262144" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"262160" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"266240" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"266256" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"393216" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"} 
"393232" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"393488" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Disabled"} 
"397312" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Enabled"} 
"397328" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397584" {$UpdateStatus = "Out of date" ;$RealTimeProtectionStatus = "Enabled"} 
"397568" {$UpdateStatus = "Up to date"; $RealTimeProtectionStatus = "Enabled"}
"393472" {$UpdateStatus = "Up to date" ;$RealTimeProtectionStatus = "Disabled"}
default {$UpdateStatus = "Unknown" ;$RealTimeProtectionStatus = "Unknown"} 
}
Write-Host ("0:" + $AV.displayname + " - " + $UpdateStatus + " - " + $RealTimeProtectionStatus)

I just used the computername as parameter! No credentials requierd!

Thans a lot! Regards Rachid

Created on Jun 4, 2018 12:30:48 PM

Last change on Jun 4, 2018 12:48:34 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

Nice! :D

Created on Jun 4, 2018 12:50:35 PM by  Stephan Linke [Paessler Support]



Votes:

0

Stephan, 1 question! :-)

Let say that the status changes, from up to date to out of date, the color bar (orange, red, green) should change from green to orange or red, can ik configure this on this type of sensor?

grtz

Created on Jun 4, 2018 1:54:21 PM



Votes:

0

Instead of 0 at the beginning of the output, you could use a variable that is changed depending on the update status in the case/switch-statement. Using lookups will then allow you to display a corresponding state :)

Created on Jun 4, 2018 5:43:11 PM by  Stephan Linke [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.