1 2 3 Previous Next 34 Replies Latest reply on Sep 20, 2019 11:21 AM by LucD

    Error when using Invoke-VMScript

    BenFB Expert

      We are trying to use Invoke-VMScript to configure a VM without network connectivity. 

      When using Invoke-VMScript cmdlet we get the error "Could not locate "Powershell" script interpreter in any of the expected locations. Probably you do not have enough permissions to execute command within guest." 

      We are using the local administrator account on the vm. We’ve tested running the same script on the VM, and it works.

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

          Can you share the Invoke-VMScript command you are using?

          Which PowerCLI version are you using?

           

          Did you check if there is anything in the vmware.log file?

          You could also enable debugging for VMware Tools (see KB1007873), and check if that if that provides more info in the log.

          • 2. Re: Error when using Invoke-VMScript
            BenFB Expert

            Hi LucD,

            I was hoping I would hear from you on this but I figured you would be at VMworld.

            We are running VMware PowerCLI 11.3.0 build 13990089.

            We tail vmware.log and this is all that's logged.
            2019-08-27T19:20:32.078Z| vmx| I125: VigorTransportProcessClientPayload: opID=2bb59b0-1-5484 seq=408585: Receiving GuestOps.CreateTemporaryFile request.
            2019-08-27T19:20:32.162Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=2bb59b0-1-5484 seq=408585: Completed GuestOps request.
            2019-08-27T19:20:32.600Z| vmx| I125: VigorTransportProcessClientPayload: opID=606ada00-e6-548d seq=408600: Receiving GuestOps.DeleteFile request.
            2019-08-27T19:20:32.664Z| vcpu-0| I125: VigorTransport_ServerSendResponse opID=606ada00-e6-548d seq=408600: Completed GuestOperations request.

            Here is the script we are trying to run.

            param(
                [parameter()]
                [System.String]
                $VM = "Test3",

                [parameter()]
                [System.String]
                $GuestUser = "sysop",

                [parameter(mandatory = $true)]
                [System.String]
                $GuestPassword
            )

            Set-StrictMode -Version Latest

            $ErrorActionPreference = "Stop"

            $GuestCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $GuestUser, ($GuestPassword | ConvertTo-SecureString -AsPlainText -Force)

            $HostCredential = Get-Credential -Message "Host Credential"

            Write-Host -ForegroundColor Green "Connecting to VIServer"
            Connect-VIServer -server $VIServer -credential $HostCredential

            $InvokeSettings = @{
                ScriptText      = "Get-ChildItem"
                VM              = $vm
                GuestCredential = $GuestCredential
                Server          = "$vCenter"
            }

            Invoke-VMScript @InvokeSettings

            p
            aram(
                [parameter()]
                [System.String]
                $VM = "Test3",
             
                [parameter()]
                [System.String]
                $GuestUser = "sysop",
             
                [parameter(mandatory = $true)]
                [System.String]
                $GuestPassword
            )
             
            Set-StrictMode -Version Latest
             
            $ErrorActionPreference = "Stop"
             
            $GuestCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $GuestUser, ($GuestPassword | ConvertTo-SecureString -AsPlainText -Force)
             
            $HostCredential = Get-Credential -Message "Host Credential"
             
            Write-Host -ForegroundColor Green "Connecting to VIServer"
            Connect-VIServer -server $VIServer -credential $HostCredential
             
            $InvokeSettings = @{
                ScriptText      = "Get-ChildItem"
                VM              = $vm
                GuestCredential = $GuestCredential
                Server          = "$vCenter"
            }
             
            Invoke-VMScript @InvokeSettings
            • 3. Re: Error when using Invoke-VMScript
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              Are you sure that VM is running a Windows guest OS with powershell installed?

              If it is a Linux guest OS, you will have to use ScriptType 'bash' and start pwsh in the code you send.

              See something similar in Invoke-VMScript not working on Debian 9

              • 4. Re: Error when using Invoke-VMScript
                BenFB Expert
                The guest is Windows Server 2016 so PowerShell is present. If we login to the console of the VM we can run the same command, Get-ChildItem, with success.
                • 5. Re: Error when using Invoke-VMScript
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  Can you try the following variation.

                  It waits till the GuestOperationsReady property says $true

                   

                  param(

                     [parameter()]

                     [System.String]

                     $VM = "Test3",

                     [parameter()]

                     [System.String]

                     $GuestUser = "sysop",

                     [parameter(mandatory = $true)]

                     [System.String]

                     $GuestPassword

                  )


                  Set-StrictMode -Version Latest

                  $ErrorActionPreference = "Stop"

                  $GuestCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $GuestUser, ($GuestPassword | ConvertTo-SecureString -AsPlainText -Force)

                  $HostCredential = Get-Credential -Message "Host Credential"

                  Write-Host -ForegroundColor Green "Connecting to VIServer"

                  Connect-VIServer -server $VIServer -credential $HostCredential

                  $vmObj = Get-VM -Name $VM

                  while (-not $vmObj.ExtensionData.Guest.GuestOperationsReady) {

                    sleep 5

                     $vmObj = Get-VM -Name $VM

                  }

                  $InvokeSettings = @{

                     ScriptText = "Get-ChildItem"

                     VM = $vmObj

                     GuestCredential = $GuestCredential

                     Server = "$vCenter"

                  }

                  Invoke-VMScript @InvokeSettings

                  • 6. Re: Error when using Invoke-VMScript
                    BenFB Expert

                    We tried the suggestion but received the same result.

                    Checking the $vmObj.ExtensionData.Guest.GuestOperationsReady variable, it was already True, so the script skipped the wait loop.

                    • 7. Re: Error when using Invoke-VMScript
                      LucD Guru
                      User ModeratorsvExpertCommunity Warriors

                      Did you enable VMware Tools debugging (the KB I linked to earlier)?

                      It might give some more info.

                      • 8. Re: Error when using Invoke-VMScript
                        BenFB Expert
                        We enabled VMware Tools debugging and repeated the process. In vmsvc.log we found relevant entries to when the script was run. I've attached the log.
                        • 9. Re: Error when using Invoke-VMScript
                          LucD Guru
                          User ModeratorsCommunity WarriorsvExpert

                          Did you already try adding the -ScriptType PowerShell parameter to the Invoke-VMScript cmdlet?

                          • 10. Re: Error when using Invoke-VMScript
                            BenFB Expert

                            It failed with this error.

                             

                            Invoke-VMScript : 9/3/2019 12:01:38 PM  Invoke-VMScript         An error occurred while sending the request.
                            At line:1 char:1
                            + Invoke-VMScript @InvokeSettings -ScriptType Powershell
                            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], ViError
                                + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

                            • 11. Re: Error when using Invoke-VMScript
                              LucD Guru
                              vExpertCommunity WarriorsUser Moderators

                              Are you sure that port 902 between the guest OS in that VM and the ESXi node on which the VM is running is open?

                              That is the port used to communicate for the GuestOperations.
                              Perhaps try disabling the FW in the guest OS as a test.

                              • 12. Re: Error when using Invoke-VMScript
                                BenFB Expert

                                We are automating our server build process and at the moment the VM has no network connectivity. We are trying to use Invoke-VMScript to configure the NIC to bring it online and continue the build.

                                • 13. Re: Error when using Invoke-VMScript
                                  LucD Guru
                                  vExpertUser ModeratorsCommunity Warriors

                                  Sorry, I stated that incorrect, I meant port 902 between the station where you run Invoke-VMScript and the ESXi node where the VM is hosted.
                                  The guest OS itself doesn't need network connectivity

                                  • 14. Re: Error when using Invoke-VMScript
                                    BenFB Expert

                                    I've verified that TCP/UDP 902 are open from the machine running Invoke-VMScript to the ESXi host where the guest resides that we are trying to interact with.

                                    1 2 3 Previous Next