Chicago Endpoint Management User Group

 View Only

How to Run a Powershell Script with Arguments in a DS 6.9 Job 

Oct 26, 2011 01:06 PM

I wanted to run a powershell script (in a Deployment Server job) that takes the computername as an argument. For whatever reason, I couldn't figure out how to modify the "common" method ( https://www-secure.symantec.com/connect/blogs/run-powershell-scripts-through-deployment-server ) to accept an argument. A nice guy suggested that I use psexec ( http://technet.microsoft.com/en-us/sysinternals/bb897553 ) with the interactive switch. IIRC, this worked, but since my DS box is running Windows 2008R2, a message pops up about a window in another session. When you kick off Powershell scripts using PSExec without the interactive switch, powershell will wait around for input (effectively hanging). That wasn't acceptable, so searched and found a workaround: http://www.leeholmes.com/blog/2007/10/02/using-powershell-and-psexec-to-invoke-expressions-on-remote-computers/ . This is what I came up with.

First, make sure that your powershell execution policy is set to enable scripts to be run on your DS. Type get-help about_execution_policies at the powershell prompt to learn more.

Also, make sure that you've run PSExec.exe once on your DS, so that you can accept the EULA, or use the PSExec switch to bypass this.

I created a CMD file that I run in a DS task that looks like:

 

"path\to\psexec.exe" -h cmd.exe /c echo . ^| powershell -file "path\to\myscript.ps1" %COMPNAME%
 
 
The "Script Run Location" is set to "Locally on the Deployment Server".
 
So, this is Altiris calling CMD.exe, which calls PSExec.exe, which calls CMD.exe, which calls Powershell.exe, which runs the script. But it works.

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Oct 27, 2011 12:22 PM

I had no trouble in doing it like so:

"Copy file to" > C:\temp\your_script.ps1

"Run Script"

powershell Set-ExecutionPolicy Unrestricted
powershell c:\temp\your_script.ps1
powershell Set-ExecutionPolicy Restricted
del /f /s /q c:\temp\your_script.ps1

Click "Next"

"Script Run Location"

"On the client computer" bullet

"Finish"

This runs my PS files just fine!

Related Entries and Links

No Related Resource entered.