7 Replies Latest reply on May 29, 2019 9:44 AM by Vineeth

    invoke operation fails

    Vineeth Hot Shot

      I am trying to install a hot fix on windows 7 machines but it is failing with below error.

      Can someone help me by correcting the script.

      $script = @'
      `$code=wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart
      function Elevate-Process { 
        param (
        [string]`$exe,
        [string]`$arguments
        ) 
        `$startinfo = new-object System.Diagnostics.ProcessStartInfo 
        `$startinfo.FileName = `$exe 
        `$startinfo.Arguments = `$arguments 
        `$startinfo.verb = "RunAs" 
        `$process = [System.Diagnostics.Process]::Start(`$startinfo) 
      }
      Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"
      '@
      foreach($vm in Get-VM 'SEW04VVM317' ) {
      Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
      }
      

       

      Error:

      Regards
      Vineeth.K
        • 1. Re: invoke operation fails
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          When you use a here-string with single quotes, there is no variable substitution.
          So there is no need to place a back-tick before the dollar signs.

          • 2. Re: invoke operation fails
            Vineeth Hot Shot

            I have tried like this and script executed with out any errors but it is not initiating the wusa.exe process inside the guest OS.

             

            $script = @'
            $code= wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart
            function Elevate-Process { 
              param (
              [string]$exe,
              [string]$arguments
              ) 
              $startinfo = new-object System.Diagnostics.ProcessStartInfo 
              $startinfo.FileName = $exe 
              $startinfo.Arguments = $arguments 
              $startinfo.verb = "RunAs" 
              $process = [System.Diagnostics.Process]::Start($startinfo) 
            }
            Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"
            '@
            $vm= Get-VM 'SEW04VVM317'
            Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
            
            Regards
            Vineeth.K
            • 3. Re: invoke operation fails
              Vineeth Hot Shot

              I have tried like this and script executed with out any errors but it is not initiating the wusa.exe process inside the guest OS.

               

              $script = @'
              $code= wusa.exe C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart
              function Elevate-Process { 
                param (
                [string]$exe,
                [string]$arguments
                ) 
                $startinfo = new-object System.Diagnostics.ProcessStartInfo 
                $startinfo.FileName = $exe 
                $startinfo.Arguments = $arguments 
                $startinfo.verb = "RunAs" 
                $process = [System.Diagnostics.Process]::Start($startinfo) 
              }
              Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command &{$code}"
              '@
              $vm= Get-VM 'SEW04VVM317'
              Invoke-VMScript -VM $vm.Name -GuestUser "admin" -GuestPassword "**" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
              
              Regards
              Vineeth.K
              • 4. Re: invoke operation fails
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                Is UAC disabled?

                Otherwise you will be getting the UAC prompt on the 'Runas'.

                • 5. Re: invoke operation fails
                  Vineeth Hot Shot

                  UAC is set to never notify.

                  If I try below variation inside the guest I can able to execute the cmd successfully and wusa.exe process will start for installation but when I pass scripttext using invoke-vmscript it executes without any error but inside the guestos wusa.exe process is not stating.

                   

                   

                  function Elevate-Process  {
                  param ([string]$exe = $(Throw "Pleave provide the name and path of an executable"),[string]$arguments)
                  $startinfo = new-object System.Diagnostics.ProcessStartInfo 
                  $startinfo.FileName = $exe
                  $startinfo.Arguments = $arguments 
                  $startinfo.verb = "RunAs" 
                  $process = [System.Diagnostics.Process]::Start($startinfo)
                  }
                  Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command C:\windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu /quiet /norestart"
                  

                   

                  Output:

                  Regards
                  Vineeth.K
                  • 6. Re: invoke operation fails
                    LucD Guru
                    vExpertCommunity WarriorsUser Moderators

                    Did you logon with the same account as the one specified on the Invoke-VMScript?

                    • 7. Re: invoke operation fails
                      Vineeth Hot Shot

                      Yes same account is used for both operation.

                      Regards
                      Vineeth.K