cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Powershell script arguments

Jump to solution

New to this community so hello all!

I'm running SAM 6.2.4, and I'm fairly adept at Powershell, but I have a small problem regarding script arguments when trying to convert one of my standalone scripts into a monitor script.

For testing, I've tried various syntax but none have been successful in trying to pull an argument from outside into the script. Below is the last attempt (which doesn't work).

pastedImage_1.png

I've tried various in the script body...

pastedImage_2.png

pastedImage_3.png

pastedImage_4.png

The script runs fine but I can't seem to find the correct syntax to parse the argument.

In the last example, the Output Result is simply 'Message:'

Also, what is the separator for multiple arguments?

Can someone ease my pain.

Thanks

Labels (1)
0 Kudos
1 Solution

Arguments are comma separated. If you want to use SolarWinds macros, it is a good practice to assign them to named variables:

pastedImage_2.png

#----------------------------------------------------------[Init variables]--------------------------------------------------------

#Pull CL arguments, the SAM way

$thisComponentID            = $args[0]

[string]$targetServer        = $args[1]

[string]$targetServerIP     = $args[2]

[string]$serviceName         = $args[3]

View solution in original post

5 Replies
Level 13

I posted a simple, sample script that shows how you can output from your PowerShell script, which can be found here: Re: Monitor and Alert on Event ID. Note how I output the value with

Write-Host "Statistic.NumberOfEvents: $NumberOfEvents";

and information with

Write-Host "Message.NumberOfEvents: Number of events is $NumberOfEvents";

Feel free to post your script and I can help guide you.

Hi it's nothing do with output, it's to do with input.

Specifically, the question is regarding what is the correct syntax (format) for the Script Arguments as inputs for a script (see image below).

My previous post was simply to get advice on what needs to be changed to the get the script argument to be used in the script?

pastedImage_0.png

0 Kudos

Sorry about that. I was caught up in the Write-Host you had in your screen shots and output comment. mlandman is exactly right with regards to input of arguments. Good luck!

0 Kudos

Arguments are comma separated. If you want to use SolarWinds macros, it is a good practice to assign them to named variables:

pastedImage_2.png

#----------------------------------------------------------[Init variables]--------------------------------------------------------

#Pull CL arguments, the SAM way

$thisComponentID            = $args[0]

[string]$targetServer        = $args[1]

[string]$targetServerIP     = $args[2]

[string]$serviceName         = $args[3]

View solution in original post

Thanks a lot for that.

Cheers

0 Kudos