What are the correct quiet install commands for VBS, Batch and Powershell when running scripts as MDT Applications?

Answered What are the correct quiet install commands for VBS, Batch and Powershell when running scripts as MDT Applications?

  • Sunday, February 17, 2013 8:21 PM
     
     

    Hey guys,

    I've been running batch files as MDT Applications with great success for several years now. Recently I've begun the proces of converting those scripts to VBScript and Powershell. Honestly I'm really struggling to figure out the proper "Quiet install command" to successfully run each script type. In fact I'm even starting to wonder if I've been using the correct command combination for batch files all these years! In the past I've always just put ' MyBatchScript.cmd ' in for the quiet install commands (without the single quotes) and thats it. Now I'm wondering if I should have been using ' cmd.exe /c "MyBatchScript.cmd" ' or something similar all this time, but do I really need to do that and (if so) why? Through trial and error I've managed to figure out that using ' cscript.exe //nologo "MyVBScript.vbs" ' seems to work best for VBScript and WSH files, but I'm totally lost on PowerShell scripts. hHas anyone here managed to successfully used all three script types (VBS, Batch and Powershell) as MDT Applications and (if so) would you mind listing the Quiet install commands you use and why?

All Replies

  • Sunday, February 17, 2013 11:25 PM
     
      Has Code

    I always use VBscript and i simply just type:

    Cscript.exe VBScript.vbs


    No qoutes or nothing unless the script has spaces in its name which i never have. But that has nothing to do if the application run quiet or not. This is how i install an MSI file with VBscript.

    Dim objWSH
    Set objWSH = CreateObject("WScript.Shell")
    objWsh.Run "msiexec.exe /i " + Chr(34) + "Msi file.msi" + Chr(34) + " /qb-!",1,1

    Chr(34) is ASCI characther for a quote ("). This will produce the following to the cmd:

    msiexec.exe /i "Msi file.msi" /qb-!

    I generally don't use Powershell cause usually powershell scripts is not allowed to be run in a windows environment unless you have enabled it.


    • Edited by Samus-Aran Sunday, February 17, 2013 11:27 PM
    •  
  • Monday, February 18, 2013 8:24 AM
     
      Has Code

    for powershell it is

    powershell.exe -File "\\SERVER\Folder\powershellscript.ps1"

    atleast when added as application.

    if you have a run powershell script in a task sequence you can simply type the location and name of the script.

    for instance %scriptroot%\script.ps1

  • Monday, February 18, 2013 8:47 AM
     
      Has Code

    for powershell it is

    powershell.exe -File "\\SERVER\Folder\powershellscript.ps1"

    atleast when added as application.

    if you have a run powershell script in a task sequence you can simply type the location and name of the script.

    for instance %scriptroot%\script.ps1

    An as i mentioned above, if the executionpolicy is set to restricted the script won't run if it is in fullOS. Then you can also add -ExecutionPolicy unrestricted to the command:

    powershell.exe -ExecutionPolicy unrestricted -File "\\SERVER\Folder\powershellscript.ps1" 

  • Monday, February 18, 2013 8:50 AM
     
     
    if added as application yes you need to have the execution policy changed but when run as a powershell script in the TS MDT handles the execution policy and doesn't need you to changed it.
  • Monday, February 18, 2013 4:54 PM
     
     
    Thanks guys,

    Yeah I think it must have been the execution policy thing that was throwing me on PowerShell. That pretty much covers all my questions with just one exception. Can somebody weigh in on the "cmd /c" thing with batch scripts? Is it a good idea/bad idea to include that? Once I get an answer on that I'll mark this answered.

  • Monday, February 18, 2013 4:57 PM
     
     

    hmm i don't really know but i used and tried both and it both works.

    with cmd /c it opens uses a new cmd to execute your script and automatically quits after that.

  • Monday, February 18, 2013 5:29 PM
     
     
    Okay, I'm typing up a quick txt-based reference for me to save on the dektop of my MDT server. I'll post it here for you guys to look at and shoot holes in. That way anyone who comes across this in the future can benefit form our discussion. Just one more final question. I forgot HTAs! Is there a the quiet install command for running an HTA as an MDT Application? Anyone ever manage to do that?
  • Monday, February 18, 2013 9:10 PM
     
     Answered

    So still no word on calling an HTA, I'm currently using a VBScript to do it but I can verify through testing that mshta.exe "myScript.hta" does not appear to work. If someone has an answer please post it here. So far this is the list of quiet install commands that I have successfully tested (except for the PowerShell one):

    Batch: 
    cmd.exe /c "MyScript.cmd"

    VBScript:
    cscript.exe //nologo "MyScript.vbs" (<- Show console window: Use of Echo and MsgBox will halt script execution)
    wscript.exe //nologo "MyScript.vbs" (<- Hide console window: Use of Echo and MsgBox will halt script execution)
    cscript.exe //B //nologo "MyScript.vbs" (<- Run in Batch mode: Suppresses display of user prompts and script errors)
    wscript.exe //B //nologo "MyScript.vbs" (<- Run in Batch mode: Suppresses display of user prompts and script errors)

    Windows Script Host (WSH):
    cscript.exe //nologo "MyScript.wsf" (<- Show console window: Use of Echo and MsgBox will halt script execution)
    wscript.exe //nologo "MyScript.wsf" (<- Hide console window: Use of Echo and MsgBox will halt script execution)
    cscript.exe //B //nologo "MyScript.wsf" (<- Run in Batch mode: Suppress display of user prompts and script errors)
    wscript.exe //B //nologo "MyScript.wsf" (<- Run in Batch mode: Suppress display of user prompts and script errors)

    Windows PowerShell (Untested): 
    powershell.exe -ExecutionPolicy unrestricted -File "MyScript.ps1" 


    Feedback is welome!

    • Marked As Answer by ZeusABJ Monday, February 25, 2013 5:17 PM
    •  
  • Monday, February 25, 2013 5:17 PM
     
     
    Well I was hoping for a little more feedback (particularly on the HTA question) but I suppose I have my answer so I'm marking this as answered. 
  • Monday, February 25, 2013 5:54 PM
     
     

    Hi,

    I never have any issues executing an HTA file using mshta.

    Only difference is that I use explicit paths, so [ C:\Windows\System32\Mshta.exe "z:\sources\customscripts\test.hta" ].

    The only downside of this method is that starting an HTA like this, will not halt the task sequencer. If you need to wait for the hta to be closed before it should continue, you should wrap the command to be executed in an executable for example, pretty sure there's other creative ways to create a looping script that closes itself after the hta has been closed.

    Kind regards,

    Stephan Schwarz


    If one of these posts answered your question or issue, please click on "Mark as answer".

    My Blog | Twitter: @Schwarz_Stephan | MCTS, MCITP, MCSA, MCC-2011.
    How to configure Windows RE/OEM Recovery Partition with MDT
    How to configure Windows RE/OEM Recovery Partition with MDT 2012 Update 1

  • Monday, February 25, 2013 6:53 PM
     
     

    Hi,

    I never have any issues executing an HTA file using mshta.

    Only difference is that I use explicit paths, so [ C:\Windows\System32\Mshta.exe "z:\sources\customscripts\test.hta" ].

    The only downside of this method is that starting an HTA like this, will not halt the task sequencer. If you need to wait for the hta to be closed before it should continue, you should wrap the command to be executed in an executable for example, pretty sure there's other creative ways to create a looping script that closes itself after the hta has been closed.

    Kind regards,

    Stephan Schwarz


    If one of these posts answered your question or issue, please click on "Mark as answer".

    My Blog | Twitter: @Schwarz_Stephan | MCTS, MCITP, MCSA, MCC-2011.
    How to configure Windows RE/OEM Recovery Partition with MDT
    How to configure Windows RE/OEM Recovery Partition with MDT 2012 Update 1

    Hi Stephan,

    I've tried this:

    mshta.exe "MyScript.hta"

    Both with and without quotes and with and without extensions. No luck either way. I just assumed my only recourse was to create a VBScript wrapper to execute it (I did get that to work BTW). I was just hoping for a way to launch it directly in MDT without the wrapper script. Maybe the explicit path trick will work, but I suppose thats a bad idea as some of my MDT servers have their share folders on drives with different driver letters. Like I said I was just hoping for a more direct command to launch the HTA, at least with VBScript it works right?