4 Replies Latest reply on Apr 8, 2020 9:16 AM by SheldonA

    PowerCLI Invoke-VMScript Error

    SheldonA Lurker

      Hello,

       

      When running the Invoke-VMScript commandlet I receive an error similar to the following:

       

      Invoke-VMScript :    Invoke-VMScript         An error occurred while sending the request.

      At line:1 char:1

      + Invoke-VMScript -ScriptText "get-service" -VM $VM -GuestUser Administ ...

      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], ViError

          + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViC

         ore.Cmdlets.Commands.InvokeVmScript

       

      My code is as follows:

       

      add-type @"

      using System.Net;

      using System.Security.Cryptography.X509Certificates;

       

      public class TrustAllCertsPolicy : ICertificatePolicy {

          public bool CheckValidationResult(

              ServicePoint srvPoint, X509Certificate certificate,

              WebRequest request, int certificateProblem) {

       

              return true;

          }

      }

      "@

       

      $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'

      [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

      [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

       

      Invoke-VMScript -vm "test centos7" -scripttext "ls" -guestuser root -guestpassword #####

       

      I tried the resolution outlined in the following thread with no success:

      Error running Invoke-Vmscript - An error occurred while sending the request. FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

       

      I'm running PowerCLI 12.0 on vSphere 6.5.0.30000 with VMware Tools version 10346.

       

      Is my code sound or is there something that I missed?

       

      Thanks in advance.

        • 1. Re: PowerCLI Invoke-VMScript Error
          LucD Guru
          Community WarriorsvExpertUser Moderators

          The error seems to occur when the Invoke-VMScript downloads the file with the output from the target VM.

          As the user in the thread, you pointed to also experienced, you might want to try my Invoke-VMScriptPlus with the Verbose switch.

          That should give you more information on what goes wrong.
          And while you are at, try the NoIPinCert switch as well.

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: PowerCLI Invoke-VMScript Error
            SheldonA Lurker

            Hello,

             

            I tried your script and received the errors below.  I configured an IP on the VM and put hosts file entries on the host running the script.  I did some research on the error and found references to proxy configurations which I am not using.

             

            VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution

            VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution

            VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution

            VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution

            VERBOSE: Created temp folder in guest OS C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26

            VERBOSE: Created temp script file in guest OS

            C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020vmware219.ps1

            VERBOSE: Created temp output file in guest OS

            C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020_outputvmware233

            VERBOSE: Copying Data to C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020vmware219.ps1

            Invoke-WebRequest : Unable to connect to the remote server

            At C:\Users\salman\Documents\test.ps1:261 char:15

            + ... copyResult = Invoke-WebRequest -Uri $fileInfo -Method Put -Body $Data

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], WebException

                + FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

             

             

            ScripText copy failed!Status

            At C:\Users\salman\Documents\test.ps1:264 char:1

            + Throw "ScripText copy failed!`rStatus $($copyResult.StatusCode)`r$(($ ...

            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : OperationStopped: (ScripText copy failed!Status  :String) [], RuntimeException

                + FullyQualifiedErrorId : ScripText copy failed!Status

            • 3. Re: PowerCLI Invoke-VMScript Error
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              Is there perhaps a proxy between your station and the VM?


              Also, did you use the -NoIPinCert switch or not?

               

              Update: I just noticed you stated there is no proxy involved.

               

              Update2: could it be that port 902 between your station and the ESXi node on which the target VM is running, is not open?

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: PowerCLI Invoke-VMScript Error
                SheldonA Lurker

                Looks like port 902 wasn't opened from the host I was running the script from to the ESXi hosts. That what was causing the issue.

                 

                Thanks a lot for your help.