none
How to deploy powershell scripts with SCE

    Question

  • Hi!

    Since SCE does not support depending programs (like SCCM), I was trying to solve the issue using a powershell script. I know, I could have done it using .bat but in the later deployment some useful powershell functionality like AD queries would be just great to further control the flow of deployment on each specific machine.

    A brief overview of what I've done.

    1. I created a .ps1 script and named it run.ps1:

     

    & '.\Uninstaller.exe' /S
    & '.\Setup.exe' /S /C My-Components.ini /X SomeOtherSettings
    & '.\ADependentApp.exe' /install AImportaintSetting /autoload
    

     


    2. Next I created a simple .bat script (named run.bat) as an execution script for the ps1 (didn't find any other working way to execute powerhsell without that + in the test env I needed the first line to simplify things and focus on the ps1 execution):

     

    powershell.exe -Command "& {Set-ExecutionPolicy -executionPolicy Unrestricted -Scope LocalMachine -Force}"
    powershell.exe -Command "& {.\run.ps1}"

     


    3. Then I copied cmd.exe and powershell.exe into my package folder.

    4. I created a new package:

    • Deploy a package from a setup file requiring additional folders (i selected my folder and in package stup file I specified cmd.exe)
    • On the Insltallation Options screen, i specified: '/c run.bat' (without quotes)

     

    The execution was successful (no errors in the windowsupdate.log or in the sce console), both scripts run, but unfortunately only uninstaller.exe (the first ps1 line) was executed. So basically the previous version of my application was uninstalled and the new one was not installed ... That's the worst case scenario for the end user ...

    Why did that happen?
    Are there any logs containing information on which executables (exe) files were run, in which order etc...?
    What's the recommended procedure for powershell scripts in deployment packages?


    Monday, January 09, 2012 2:25 PM

Answers

All replies

  • Hi,

    Please refer to this thread firstly:

    Run Batch file or another package after a package deployment
    http://social.technet.microsoft.com/Forums/en-US/systemcenterdevelopment/thread/976d2a0a-209d-442a-b566-c726dc937330

    If I use a .bat file to install several softwares in order, I need SLEEP.exe command to make the system wait sufficient time for the first command to finish. You may need it in your script too.

    Thanks,


    Yog Li

    TechNet Community Support

    Wednesday, January 11, 2012 7:41 AM
    Moderator
  • Yog Li, thank you for your reply. It's nice to see a workaround is possible!

    It'd be really interesting to know why sleep is needed at all, since it unnecessarily complicates otherwise really simple things...

    Monday, January 16, 2012 10:21 AM
  • Hello,

    Glad to hear the workaround helps.

    Generally, if you use the script or .bat file to run several programs, they will be run one by one. But you cannot make sure the first program finished its process before the second program start. So we need to use the SLEEP.exe.

    Thanks,

     


    Yog Li

    TechNet Community Support

    Tuesday, January 17, 2012 10:10 AM
    Moderator