Capture system restarts or not when executing PowerShell remotely

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) 
     $SB1={
             Start-Process -FilePath 'wusa' -ArgumentList "$path /extract:c:\updates" -wait -PassThru

    $SB2={
            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

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

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

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
$process.ExitCode()