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>"
Add comment