Hi Team,
I am attempting to create a powershell script monitor component but am receiving the error “Not Defined” when testing the script against my target machine. The script in question is below, and basically just checks the filecount in a folder.
[int]$fileCount = ( Get-ChildItem D:\backups | Measure-Object ).Count;
if ($fileCount -lt 5) {
Write-Host "Statistics.status: 100"
Write-Host "Message.status: Down"
exit 2
}
else {
Write-Host "Statistics.status: 0"
Write-Host "Message.status: Up"
exit 0
}
As this was not working (output was "Not Defined") I simplified the script to below, but this still does not work.
write-host "Statistic.status: 100”
write-host "Message.status: Down”
I am using the "Windows Powershell Monitor" component with the following settings.
Execution Mode - Remote Host
Use HTTPS - No
URL Prefix - wsman
Port - 5895
Run the script under specified account - No
Script Output #1
Unique ID - status
DisplayName - status
Warning - Greater than 0
Down - Greater than 50
I should be getting a output of Down according to the above configuration.
I have tested WinRM and powershell is able to be executed remotely from the Orion server to the target machine and it works.
Orion Server
==========
PS C:\Windows\system32> Enable-PSRemoting -Force
WinRM is already set up to receive requests on this computer.
WinRM is already set up for remote management on this computer.
PS C:\Windows\system32> Test-WsMan **hostname**
wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 2.0
PS C:\Windows\system32> Invoke-Command -ComputerName **hostname** -ScriptBlock { echo $null >> D:\backups\touch.txt } -credential**user**
PS C:\Windows\system32> Invoke-Command -ComputerName **IP** -ScriptBlock { echo £null >> D:\backups\touch.txt } -credential **user**
When either of the two commands above are run(to the hostname or IP) I can see a file generated in D:\backups\touch.txt. From Wireshark on the target device I can see this traffic hitting TCP port 5985, the WinRM port.
However when I test the script through the component GUI targeting the device in question, I do not see any traffic hit the target device at all on port 5985 and I simply receive an output error of “Not Defined”. It appears as if the script isn’t even bring ran on the remote device. I have updated and confirmed the credentials being used through the SAM credential manager is correct (the same ones tested with the Invoke-Command above).
Any advice and suggestions would be welcome. Many thanks!