Video Screencast Help

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

Created: 26 Oct 2011 • Updated: 26 Oct 2011 | 1 comment
Language Translations
chi-user's picture
+2 2 Votes
Login to vote

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.

Comments 1 CommentJump to latest comment

Benjamin Fuller's picture

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!

You break IT, I fix IT!

+1
Login to vote