All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
bgorton
Posts: 11 Joined: Fri May 03, 2019 8:33 am
Post
by bgorton » Wed Dec 11, 2019 3:46 pm
I have the following PS script I am trying to run thru Script Manager
Code: Select all
$ELSystem = ".\EL-System.log"
$ELApp = ".\EL-apps.log"
#end region variables
#--- SCRIPT ---#
#region script
$system = Get-WinEvent -ComputerName $Args -FilterHashtable @{logname='system';Level=2} | Where-Object { $_.TimeCreated -gt $begin} | Format-Table -Autosize | Out-File $ELSystem -Append
with $args being defined in the Params field as the hostname of the computer I am running the test against. I can run this script in PS itself while specifying in the script the hostname, but when I run thru HostMonitor, I get the following error:
Code: Select all
Get-Winevent : Cannot convert 'System.Object[]' to the type 'System.String'
required by parameter 'ComputerName'. Specified method is not supported.
KS-Soft
Posts: 13012 Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:
Post
by KS-Soft » Thu Dec 12, 2019 12:27 pm
1) You are sending hostname as 1st parameter of the script?
Then use
$args[0] or
$($args[0]) instead of $Args
2) If you are using script for ShellScript test, then you need to return correct result to HostMonitor
https://www.ks-soft.net/hostmon.eng/mfr ... m#shellres
3) You may check if parameter passed to the script or someone forgot to specify hostname, e.g.
Code: Select all
$statusUnknown = "ScriptRes:Unknown:"
$statusOk = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
if (!$args[0]) {
echo $statusUnknown"Hostname not specified"
exit
}
..your code...
echo $statusOk
And may be add some Try..Catch block for error handling.
Regards
Alex