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

EXE/Script Advanced Powershell Timeout PE018

Votes:

0

When I comment the Invoke-Command line the script completes successfully when not return Timeout PE018

My code:

##USB MONITOR

##param(
##[string]$DEVICE
##)

$DEVICE = "USB_HUB_01"

## CREDENTIALS
$username = "test.local\testprtg"
$password = Get-Content "C:\PRTG\Custom Sensors\EXEXML\Key.txt" | ConvertTo-SecureString 
$credential = New-Object System.Management.Automation.PsCredential($username,$password)
$server = 'server.test.local'
$RESULT = "0"


$ScriptBlockContent = {

		$MORPHOUSBREMOTE = gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)}
		return $MORPHOUSBREMOTE.DeviceID
}


##$session = New-PSSession -computerName $server -credential $credential
$MORPHOUSBLIST = Invoke-command -credential $credential -scriptblock $ScriptBlockContent -computerName $server
##Remove-PsSession $session.id


foreach ($i in $MORPHOUSBLIST){
	
	
		if ($DEVICE -eq $i){
			$RESULT = "1"
			break;
		}else{
			$RESULT = "0"
		}
	
}

	"<prtg>"
			"<result>"
			"<channel>MSG</channel>"
			"<value>$RESULT</value>"
			"</result>"
	"</prtg>"

powershell prtg snmp

Created on Aug 22, 2018 4:02:29 PM



1 Reply

Votes:

1

WMI and PowerShell - this might be an issue. You might possibly face a x32 and x64 issue here.

If so, you can work around it - look at the following link - it talks about a Parser-Script to bypass this issue. https://www.it-admins.com/monitoring-shadow-copies-with-prtg/

In the end it is a similar situation where WMI is in use.

Btw. - you have code you wouldn't need in your loop - the ELSE case is obsolete cause you set the variable way above to 0 and break it the second you change it anyways.. This should be sufficient:

foreach ($i in $MORPHOUSBLIST){
	if ($DEVICE -eq $i){
		$RESULT = "1"
		break;
	}
}

Regards

Florian Rossmark

www.it-admins.com

Created on Aug 23, 2018 6:43:00 PM




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.