OSD and Powershell
Hello,I'm running an OSD task sequence with various applications and all is going well. Untill the sequence gets to the point it has to run a Powershell script to configure the final steps. Adding some Windows features, changing CDROM drive letter and some other stuff.I've got a nice Powershell script for that which, when manually executed, runs without problems but when I try to run it from a program in an SCCM task sequence it doesn't get executed at all.I know PS settings are set to Restricted as default and so preventing all scripts from running. This is easily fixed by adding a registry setting to both the 32- and 64-bit key. This key is set to RemoteSigned and so allows for the execution of local scripts, the advertisement is set to download content locally before executing. Following this a Powershell script should run without problems, it doesn't however. My question is quite simple, is there a clear cut way to execute a Powershell script during OSD? I've tried signing the script but then you'd stumble on the fact that the machine doesn't have the root certificate used to sign the script...
March 2nd, 2010 10:33am

Check this post by Michael Niehaus http://blogs.technet.com/mniehaus/archive/2009/09/22/running-powershell-scripts-as-part-of-a-task-sequence.aspx might give you an idea or two!Michael Petersenhttp://kongkuba1.spaces.live.com
Free Windows Admin Tool Kit Click here and download it now
March 2nd, 2010 11:15am

Thanks for your reply, allthough the information in this post was quite handy and to the point there's still this little thing of the Powershell Executionpolicy. Out of the box it's set to Restricted. In the blogpost mentioned there's a tip to run a commandline to set the execution policy to unrestricted. However, when I add this command line it gets processed by the task sequence (confirmed in the smsts.log) it actually runs, exitcode 0, but there's no result. I made a tasksequence with just this command line for testing purposes, I've used domain admin credentials to run it, I've build the command line with and without quotes, I've used the 'cmd /c' method and still no result. I know you can influence the powershell executionpolicy with group policy, but when running a task sequence policies aren't applied yet so that won't help either for the deployment sequence.
March 19th, 2010 9:41am

hi, i am facing the same problem,i have a powershell script which just creates a folder in the target machine when i am executing the script through sccm task sequence ,ts runs but the folder is not created & when the script is executed manually it runs fine(when the executionpolicy is changed to unrestricted).... i advertised the ts to the machines where the executionpolicy is set to unrestricted but the folder is not created. if you have found out a solution to this problem ...plz help thanks & regards. pranay
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 3:25pm

I use a workaround... but not a solution... caal the In the tasksequence cal a script LaunchPS.cmd with following lines in it powershell -command "& {Set-ExecutionPolicy -Scope LocalMachine Unrestricted -Force}" powershell -command .\sendmail.ps1 works well...
June 22nd, 2011 4:29pm

hi jeroenda, i tried this in my lab but it doesn't worked....so i created a batch file and named it as powershell.bat and in the bat file i entered the command powershell -command "& {set -executionpolicy -scope currentuser -executionpolicy unrestriceted}" powershell.exe %~dp0%1 and then created a package with this bat file,associated this package in the ts and in the command linei gave the command powershell.bat b.ps1 but it's not working ....need a solution for this... thanks pranay.
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2011 1:13pm

hi, finally figured it out....created a .cmd file with powershell commands in this file .... created a package and in the program part gave the name of the file to be executed as command line...deployed a new machine and finally the script worked.... thanks & regards, pranay.
June 24th, 2011 8:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics