Monthly Archives: January 2012

Running powershell scripts as part of a Task Sequence

I’ve seen various ways of running powershell scripts as part of a Task Sequence some that have worked well some not so well.  The method that I have had 100% success rate with is

powershell.exe -command “set-ExecutionPolicy Unrestricted; cpi %SCRIPTROOT%\scriptname.ps1 -destination c:\; c:\scriptname.ps1; ri c:\*.ps1; set-ExecutionPolicy restricted”

This command basically drops the excution policy to unrestricted, copies the script to the local c:\, executes the script, removes the script and then sets the excution policy back to restricted.

The above assumes that you are using MDT or SCCM with MDT integrated.

If you are just using SCCM with no MDT integration, all you need to do is create a new package which contains your script and then add a step in your Task Sequence to run a command line, selecting the Package that contains your script.

Your command line should then look like:

powershell.exe -command “set-ExecutionPolicy Unrestricted; cpi scriptname.ps1 -destination c:\; c:\scriptname.ps1; ri c:\*.ps1; set-ExecutionPolicy restricted”

Clearing the client App-v Cache

When troubleshooting applications that have already been sequenced and published or even just testing applications as you sequence them, clearing the client cache is normally the first thing to try to resolve any issues, in most cases this normally solves the problem.

To clear all applications in the cache issue the command sftmime delete obj:app /global /complete from a cmd prompt.

In cases where you only want to clear specific applications, you first need to obtain a list of applications already in the client cache using the command sftmime query obj:app /short.  Once you have the list of applications, you can remove individual applications from the cache using the command sftmime delete package:”app name”.