5

Is there a way to make powershell scripts run under the applications list so that when you install from the MDT image you can select which scripts you want to run?

I can run the scripts fine as scripts but every attempt I've tried the scripts will not execute.

This is how I am trying to do it, but they don't execute. (I link to the Script under the Install Applications under Task Sequence. So far I've come to conclude Microsoft does not allow PowerShell Scripts to work this way without some serious hacking around.

enter image description here

EDIT:

So after trying several ways and doing research this is what I have now:

I am trying this:

powershell -noexit "& "'\\SERVER.com\ImageDeploymentShare$\Scripts\script_tes_2t.ps1'

Working Directory is:

.\%SCRIPTROOT%

But I am getting this: enter image description here

I saw something like this posted on technet but surely this is to the extreme?

Filename RunPowerShell.cmd
Powershell -Command Set-ExecutionPolicy Unrestricted
Powershell.exe -file "%~dp0%1"
Powershell -Command Set-ExecutionPolicy AllSigned

Filename App1.ps1
Dir

Execute this with
[fulle_Path_if_needed\]RunPowerShell.cmd App1.ps1
Jason
  • 3,821
  • 17
  • 65
  • 106
  • Have you tried doing this?: `powershell.exe yourcommandsgohere /yadayadayada` – Elliot Huffman Jul 07 '14 at 20:10
  • If you already tried this then look at this: http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/ – Elliot Huffman Jul 07 '14 at 20:12
  • If that answers you question then I will make an answer that fits the info I just gave you. – Elliot Huffman Jul 07 '14 at 20:12
  • Trying to make heads and tails out of that site. They have so many quotations in there. I do appreciate your help Elliot! – Jason Jul 08 '14 at 02:50
  • Try this: `powershell “\%SCRIPTROOT%\script_tes_2t.ps1` Where the Powershell script is in your servers' deployment share in the scripts folder along with your other LTI/ZTI scriptes – Elliot Huffman Jul 08 '14 at 12:57
  • Make sure that this is after Windows is updated (if you have that step) and your programs are installed (some might add functionality). If this does not apply to your then just run it after the system starts up. You do not need the `-noexit` flag because you want automated. If you have that flag then the system will not close itself. – Elliot Huffman Jul 08 '14 at 12:59
  • Yea, I used noexit for debugging. So I finally got it to work with some other tricks. Thanks Elliot! – Jason Jul 08 '14 at 14:53
  • Can you post the answer or if I solved it can you please let me know? Thanks! – Elliot Huffman Jul 08 '14 at 15:58

2 Answers2

4

I don't know about MDT, but running UNC-located PowerShell scripts from the commandline goes something like powershell -ExecutionPolicy bypass -file \\path\to\file.ps1.
It works from cmd (without any security prompts):

Running UNC-based PowerShell scripts from commandline

Nitz
  • 1,018
  • 1
  • 8
  • 18
  • If you are running an unattended script I also recommend adding `-NonInteractive -NoProfile` when calling Powershell.exe – Greg Bray Aug 11 '14 at 05:32
2

in the 'quiet install command' of your application:

powershell.exe -executionpolicy bypass -noprofile -noninteractive -file ".\[yourscriptfile].ps1"

There main issue with just putting the ps1 file as the command is the executionpolicy, since the default is restricted. Even changing executionpolicy to remotesigned the script will not run because it's a UNC path.