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

ARM not passing specified parameters to powershell script.

Jump to solution

So I wish to use ARM to run a powershell script when it creates the user.

The user creation part all works successfully, however when it runs the powershell script this is what happens:

I've configured it to run this script:

"C:\ProgramData\protected-networks.com\8MAN\scripts\analyze\ExchangeParam.ps1"

Parameters:

"{samaccountname}"

Contents of the "ExchangeParam.ps1" script:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://FQDNExchangeServer/PowerShell/ -Authentication KerberosImport-PSSession $Session

$args[1] = $samaccountname

Send-MailMessage -From 'SolarwindsARM@contoso.com' -To 'myworkemail@contoso.com' -Subject 'Test mail' -SmtpServer 'exchangesmtp.contoso.com' -Body "The parameter name is: $samaccountname and being passed through the script correctly."

I create a user in ARM and ensure the checkbox is ticked to Start the external program/powershell script.

The user I created was called: Test User

samaccountname:     usetes

When I go to look at the logs, the {samaccountname} parameter which is passed to the powershell script, is just being appended to the end of the powershell script.. as you can see below:

Custom executable finished with output: [000] powershell.exe -inputformat none -File "C:\ProgramData\protected-networks.com\8MAN\scripts\analyze\ExchangeParam.ps1" usetes

The user is created successfully and I receive the email:

The parameter name is: and being passed through the script correctly.

So the script isnt getting the parameter passed to it correctly... All ARM is doing is appending the {samaccountname} parameter to the end of the powershell command and thats it..

Am I missing something here??? All the doco I can find online has the exact same info and all correct... I'm not sure what I'm doing incorrectly here????

0 Kudos
1 Solution
Level 10

The error is not coming from ARM but your script.

You're defining

$args[1] = $samaccountname

$samaccountname is empty, it's nowhere defined.

$args[1] does not exist and you define it as the empty $samaccountname value.

{samaccountname} is actually $args[0] since it starts counting at 0.

The correct line must be:

$samaccountname = $args[0]

View solution in original post

4 Replies
Level 7

Thank you Bjoern,

That has worked. The information I had was what was originally given to me to use to pass the info to the script. Many thanks for your assistance

0 Kudos

You're welcome 🙂 glad I could help.

0 Kudos
Level 10

The error is not coming from ARM but your script.

You're defining

$args[1] = $samaccountname

$samaccountname is empty, it's nowhere defined.

$args[1] does not exist and you define it as the empty $samaccountname value.

{samaccountname} is actually $args[0] since it starts counting at 0.

The correct line must be:

$samaccountname = $args[0]

View solution in original post

For further explanation: what ARM does is correct, that's how you hand over an argument to a PowerShell script.

The first argument is always $arg[0], the next $arg[1] and so on...

Or you can handle them differently in your script:

param(

[string] $password,

[string] $givenname,

[string] $sn

)

But they are always handled in the order they are handed to the script.

And in the script it's always the value on the left side of the = that is defined by whatever is on the right side of it.