powershellvirtual-machineinvoke-commandstart-process

Start-Process is not working in Invoke-Command


$upgradeInvoke = Invoke-Command -Session $session -ScriptBlock {

        try {
            Shutdown.exe /r /f /t 1200 /d p:4:2 /c "Triggerd Reboot Timer for 20 minitus"
    
            $arguments = "/s", "/v`"/qn REBOOT=ReallySuppress`""
            $process = Start-Process -FilePath $using:setupFullPath -ArgumentList $arguments -PassThru -Wait -Verb runas
            Write-Output $process.ExitCode
        }
        catch {
            Write-Output "An error occurred: $($_.Exception.Message)"
        }

} -WarningAction SilentlyContinue -ErrorAction Stop

I'm Trying to install VMTools in a remote machine after disabling UAC, The Invoke is working and I could see User32 Event logged in EventViwer for reboot. But Start-Process is not getting triggered. The same script is working when any other user is just logged in via RDP or Direct Console. It looks weird, doesn't it? Moreover, its working fine with Windows Server 2012 R2, 2016 and 2019 Standard. It's not working with Windows 2022 Standard.


Solution

  • The 'cmd /c' method didn't work in Windows Server 2012 R2, Hence I've clubed both commands. $arguments = "/s", "/v", "/qn", "REBOOT=ReallySuppress" $process = Start-Process -FilePath "cmd.exe" -ArgumentList "/c "$using:setupFullPath" $arguments" -Wait Write-Output $LASTEXITCODE This is working in all the Windows versions