KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Error in Powershell Script

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
bgorton



Joined: 03 May 2019
Posts: 11

PostPosted: Wed Dec 11, 2019 3:46 pm    Post subject: Error in Powershell Script Reply with quote

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
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Thu Dec 12, 2019 12:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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

KS-Soft Forum Index