|
View previous topic :: View next topic |
Author |
Message |
bgorton
Joined: 03 May 2019 Posts: 11
|
Posted: Wed Dec 11, 2019 3:46 pm Post subject: Error in Powershell Script |
|
|
I have the following PS script I am trying to run thru Script Manager
Code: |
$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: |
Get-Winevent : Cannot convert 'System.Object[]' to the type 'System.String'
required by parameter 'ComputerName'. Specified method is not supported.
|
|
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Thu Dec 12, 2019 12:27 pm Post subject: |
|
|
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/mframe.htm#tests.htm#shellres
3) You may check if parameter passed to the script or someone forgot to specify hostname, e.g. Code: |
$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 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|