SCCM – Using Powershell in a Task Sequence

20 Mar

Using System Center Configuration Manager (SCCM),  I was trying to deploy a task sequence for lab computer imaging. I was trying to use a batch file to run a Powershell script that makes shortcuts in a specified folder, but the command prompt kept throwing an error. This error happend everytime the command prompt tried to execute the Powershell script.

Source Code

  •  Here is my source code (batch file contents).
    REM Installing  Mathematica 8
    Mathematica_8.0.4_WIN.exe /silent /suppressmsgboxes
    REM Run Shortcut Script
    powershell .\Make-Shortcuts_Mathematica8.ps1


  • When I tried to run the command:
    powershell .\Make-Shortcuts_Mathematica8.ps1
  • I get an error that states:
    File C:\workingtemp\mathematica8\Make-Shortcuts_Mathematica8.ps1 cannot be loaded. The file C:\workingtemp\mathematica8\Make-Shortcuts_Mathematica8.ps1 is not digitally signed. The script will not execute on the system. Please see “get-help about_signing” for more details..
    At line:1 char:34
    + .\Make-Shortcuts_Mathematica8.ps1 <<<<
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeExecption 
  • The error looks like this:


  • Here is the solution, this command will work for any powershell script.
    powershell  -noprofile -command "& {$variable = Get-ExecutionPolicy:If((Get-ExecutionPolicy) -ne 'Unrestricted'){Set-ExecutionPolicy unrestricted -force;}; .\<YOURSCRIPTHERE>; Set-ExecutionPolicy $variable}"
  • This command will check if the “Execution Policy” is set to unrestricted. If not it will set it to unrestricted, then run the target powershell script. Finally, the command will set the Execution Policy back to the previous value.

Please leave a comment for any questions/problems!


Posted by on March 20, 2012 in Uncategorized


Tags: , , , ,

4 responses to “SCCM – Using Powershell in a Task Sequence

  1. Gene Evans

    May 1, 2012 at 8:12 pm

    In Powershell v2 you can simply do the following:
    powershell -ExecutionPolicy Bypass -File .\

  2. Trevor Stuart

    July 5, 2012 at 9:51 pm

    Thank you Gene, the comment you posted helped with an issue I was having. The issue was I had all my powershell scripts set up, and created programs in a task sequence in SCCM 2012 for deployment. During the image process, every step “completed” successfully, but unfortunately nothing got installed…no errors, and no results. Now, when I use the command you wrote above, some install, and some do not…any ideas?

  3. erikcurtis

    September 19, 2012 at 9:10 pm

    Better yet… within SCCM 2012 you can configure the computer agent within Administration > Client Settings to bypass the powershell Execution Policy. when running via SCCM.

  4. David Wallis

    April 10, 2014 at 5:40 pm

    Slight mistake in that you have put :if but it should be ;if

    powershell -noprofile -command ” .\; Set-ExecutionPolicy $variable}”



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: