Wait for remote action, then continue? RRS feed

  • Question

  • Fairly new to PowerShell...

    I am trying to automate as much of the upgrade process as I can for a fairly complex application that spans across many servers. I'm not sure what I want to do is possible, and I wasn't sure how to articulate it into a Google Search, so I decided to try asking some fellow human beings. 

    The application installs/upgrades have an order of operations, and the first couple of installs must complete before the rest can begin.

    1. Install to SQL Server, which can take a long time. It has to complete successfully before the next step can run.

    2. Install to Service Bus for Windows server or farm. This can't begin until the SQL install completes, and must be completed before the rest of the installs begin.

    3. Web and misc. Windows servers that run the application's Windows services. These can run all at once, but not until steps 1 and 2 complete successfully.

    I want to run this whole process remotely from a server in the same network. I have worked out remotely deploying installers and their response files to the various servers from this central location, but I am trying to figure out how (if possible) I could get the second server to wait until the first server is done, and then begin its install process, and so on.

    Is there a way to make the process wait for some kind of acknowledgement of success (or failure I supposed) from the first step, and then begin the next step?

    Monday, May 20, 2019 4:28 PM

All replies

  • PowerShell jobs might be a good approach

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Monday, May 20, 2019 4:40 PM
  • I will take a look at this. Thank you!
    Monday, May 20, 2019 5:00 PM
  • What you are asking to do is addressed in DSC.  DSC allows you to state dependencies so installs will only apply when a dependency becomes available.  All checking and I stalling is handled automatically. 

    There are DSC modules for most MS software and custom modules can be easily built for non-MS installs.




    Monday, May 20, 2019 5:29 PM
  • You might want to look at Chocolaty.

    The computing world is headed to the cloud using automated build tools like that. We started using Puppet and Chocolaty just as I "got retired", so I don't have a lot of experience with these tools. I would expect you to have a bit of a learning curve to get it set up, but in the long run it would position you to use it for any software package needed on your servers. 

    What is Chocolatey?

    Chocolatey is a package manager for Windows (like apt-get or yum but for Windows). It was designed to be a decentralized framework for quickly installing applications and tools that you need. It is built on the NuGet infrastructure currently using PowerShell as its focus for delivering packages from the distros to your door, err computer.

    Chocolatey is a single, unified interface designed to easily work with all aspects of managing Windows software (installers, zip archives, runtime binaries, internal and 3rd party software) using a packaging framework that understands both versioning and dependency requirements. Chocolatey packages encapsulate everything required to manage a particular piece of software into one deployment artifact by wrapping installers, executables, zips, and scripts into a compiled package file. Chocolatey packages can be used independently, but also integrate with configuration managers like SCCM, Puppet, and Chef. Chocolatey is trusted by businesses all over the world to manage their software deployments on Windows. You’ve never had so much fun managing software!

    Monday, May 20, 2019 5:38 PM
  • Thank you. I've been trying to get IT to look into that for other reasons too (e.g. Roles and Features prerequisites)
    Wednesday, May 22, 2019 3:37 PM
  • I know that the vendor of the application that I am working with uses Jenkins and Chef to do what I am attempting to do, but that's probably not an option for me because I'd have to get Corp IT involved and sell them on all of that. 
    Wednesday, May 22, 2019 3:38 PM
  • because I'd have to get Corp IT involved 
    Absolutely, your IT staff has to drive this direction. You can't (shouldn't) do it by yourself.  
    Thursday, May 23, 2019 2:05 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Monday, June 3, 2019 7:48 AM
  • It hasn't been resolved yet, however I think my best (only) option for now is to try to use PowerShell Jobs to accomplish this.

    When I've got this worked, I will reply with the details here. Likewise, I may have more questions along the way as I try to get this working. 

    Tuesday, June 4, 2019 7:46 PM
  • So it looks like running things as a job is definitely the way to go, but during my testing I am having an issue.

    My PowerShell successfully remotely executes to the application's .BAT file (which calls the .EXE) and I can even get feedback from by running Receive-Job and see that the .BAT did call the .EXE successfully, but that's where the whole process seems to stall. 

    The validations should only run for a few seconds and output a success message. I only see the message stating that it executed. If I go to the remote machine, I can see the CMD process in the Task Manager - Details; it should be complete. The other reason I know it's not running all the way through is because no matter what, the process creates a log file, and that isn't happening.

    Just remotely executing a simple .BAT to create a folder on the machine works no problem, so I know in theory this is all possible. I think I am probably missing something simple here, but I am not sure what it is. 

    Thursday, June 20, 2019 1:29 PM
  • Put logging commands in the bat file.

    echo %date% %time% Install beginning. >> c:\logs\install.log
    echo %date% %time% Contents of our directory. >> c:\logs\install.log
    dir c:\somefolder  >> c:\logs\install.log
    echo %date% %time% Calling app install exe. >> c:\logs\install.log
    setup.exe /parm1 /parm2  >> c:\logs\install.log
    set rc=%errorlevel%
    echo %date% %time% Install ended, return code %rc% >> c:\logs\install.log
    echo %date% %time% Install end. >> c:\logs\install.log

    Thursday, June 20, 2019 3:56 PM
  • You cannot remotely install a program with a simple batch file.  The installer will terminate when the batch file terminates.

    TO do this use a session and check for the setup or MSI to be completed before ending the session.


    Thursday, June 20, 2019 4:10 PM
  • That's actually the way the application comes/is installed.

    Batch file calls executable, determines location of the logs, and points the install at the response file for install variables. It also provides a couple of switches for things like repair install or dry run (only runs validations). 

    The only thing I am doing different than I normally would do is that I am calling the .BAT from a remote computer using PowerShell and applying -AsJob as opposed to opening a CMD prompt on the machine itself and running the .BAT from there.

    I can see it trying to work, it just doesn't seem to progress past launching the executable. 

    Thursday, June 20, 2019 5:55 PM
  • Yes and the batch is terminating before the install is complete.  This causes the session to end with no install and no output.

    Try this.

    Use "Enter-PsSession" and run the batch at the remote prompt.  Next run a tail on the setup log.  You should see that the install is continuing after the batch completes.

    This is common with many installer when run in silent mode. 

    There are many blogs discussing how to over come issues with remotely installing SQLServer.  The issues are different for every version.

    Running the batch at a remote prompt will give you more information.


    Thursday, June 20, 2019 6:11 PM
  • Thank you.

    The reason for running it as a job is because I have several of these that I want to run at the same time, and wanted to do it from a central location and be able to see output there re: the status of the install process.


    $computers = gc "c:\<directory>\<subdirectory>\servers.txt"
    foreach ($computer in $computers) {
    Invoke-Command -ComputerName $computer -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /c 'C:\<directory\<subdirectory>\install.bat'"} -AsJob

    There is a .PS1 on the remote computer(s) that I could use instead of the .BAT file if that makes a difference, but I couldn't get the syntax correct to get it to execute. It has a lot of variables applied to it when run straight from the prompt. 

    Thursday, June 20, 2019 7:16 PM
  • Then you will have to write a script that keeps the session alive until the install is complete.

    Start by testing at a remote prompt to get an understanding of what is happening.  Once you understand how to detect the installation completion you will know what has to be written to make this work.

    There is  no simple answer.  You must understand every element of the process and its behaviors and then add script to manage the seesion from the behaviors.  This is what we call "programming" or "automation".


    Thursday, June 20, 2019 7:21 PM