Capture system restarts or not when executing PowerShell remotely

This topic contains 3 replies, has 2 voices, and was last updated by  Rob Simmers 1 year, 2 months ago.

  • Author
  • #65556


    Hi all I am having the following script which updates the software remotely

    $path= 'c:\mysw-x64.msu' #c:\_temp\W2K12-KB3134759-x64.msu
    Invoke-Command -Session $psSession -ArgumentList $path-ScriptBlock { param($path) 
                 Start-Process -FilePath 'wusa' -ArgumentList "$path /extract:c:\updates" -wait -PassThru
                Start-Process -FilePath 'dism' -ArgumentList "/online /add-package /PackagePath:c:\updates /IgnoreCheck /Quiet" -PassThru -wait
          Invoke-Command -ScriptBlock $SB1
          Invoke-Command -ScriptBlock $SB2

    This executes fine and system is getting restarted but I need to check whether it actually restarts or any issues while updating is it possible to do so or if it successfully restarts I need a return code

  • #65586

    Rob Simmers

    You don't want the reboot to be initiated by your installation command. For instance, for wusa you would specify a /norestart, let the command finish, get the exit code (e.g.3010-reboot required) and then use Restart-Computer to initiate a system reboot. Additionally, you may need to call the command with Start-Process -Wait to ensure that the command completes or it will likely run the command and immediately reboot the system. If you do some searches on running MSI with Powershell, you should find plenty of examples

    • #65686


      Hi Rob I added /norestart but still I am not getting the exit code

  • #65734

    Rob Simmers

    You can find answers to your questions with simple searches like "Start-Process exit code".:

    $process = Start-Process -FilePath 'wusa' -ArgumentList "$path /extract:c:\updates" -wait -PassThru

You must be logged in to reply to this topic.