VMware Cloud Community
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Invoke-VMScript - An error occurred while sending the request

Hi,

I am writing a script that use invoke-vmscript and Copy-VMGuestFile but they throw an error when I run them again the vcenter server.

Here one example:

Invoke-VMScript -ScriptText $NetworkSettings -VM $VMName -GuestCredential $credential

Invoke-VMScript : 01/04/2019 10:56:52   Invoke-VMScript         An error occurred while sending the request.

At C:\Users\user\Documents\vscodeProjects\SupportTeam\Vmware-Automation\Actions\CONFIGNET\ActionCONFIGNET.psm1:43 char:5

+     Invoke-VMScript -ScriptText $NetworkSettings -VM $VMName -GuestCr ...

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

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

    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

To notice that I connected correctly to the vcenter before run the Invoke-Script and that the script contained in $NetworkSettings has been run correctly on the guest VM. The only problem seems to happen when the Invoke-VMScript try to read the result. If I run the Invoke-VMScript again the physical host instead the VCenter everything is working.

Vcenter, physical host and the machine who the invoke-vmscript are in the same network.

Same problem if I use the Copy-VMGuestFile

Any ideas?

0 Kudos
27 Replies
LucD
Leadership
Leadership
Jump to solution

Not really.

The Invoke-VMScript cmdlet comprises several steps: simplified it consists of creating temp files in the guest OS, running the command in the guest OS from one of those file and storing the output of the command in another temp file, and finally downloading the result.

It is in that last stage, the download of the temporary file, with output from the command, that things go wrong.

This operation fails due the invalid certificate, and that is due to the fact because the internals need to use a web function Get from the ESXi node to receive that file.

Contrary to most of the other steps which use some of the GuestOperations methods.

You can simulate this retrieval from the ESXi node by doing a Get-WebRequest, with the errors I have shown before.

An that kind of failure is not recorded in any of the VMware logs afaik.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

I can confidently say that I am getting the same error as follows,:

Invoke-VMScript -  An error occurred while sending the request

One thing I observed was it takes sonetiso , around 5 minutes to come out of the command execution and error out.

I suspect that my command is not getting executef.

0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

LucD

I am not just mentioning about failures in the log file.

I assumed that there will be some logging activity if a command is issued using invoke-vmscript.

Vijay

0 Kudos
LucD
Leadership
Leadership
Jump to solution

To check if your command is executed in the guest, you could use the method Chris just proposed.


The availability of log entries depends on where things go wrong.
If there is an issue with any of the methods in GuestOperations, you could activate debug logging for the VMware Tools.

See KB1007873

That it takes 5 minutes could probably be due to some timeout somewhere.

Could be the cmdlet waiting for the output file to be downloaded.
A network trace should be able to tell you at what stage the problem occurs.

As a general remark; you seem to forget that this is a forum where users try to help other users, this is not VMware Global Support.
If you feel that there is a bug or a problem in the cmdlet, you should open a SR.

That is, after all, why you pay for a Support Contract.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

LucD,

Right  now I am not in a position to say if it is a bug.

I am trying to figure out where I am going wrong with the command execution.

As I mentioned in my first comment,

I have two ESXi clusters managed by one VCenter. The invoke-vmscript is working well with one cluster where I was able to execute and get output. And I have the problem with VMs hosted on the other ESXi cluster, and recieve this error. I turned on the debug logging, but I don't see anything obvious in the logs when I run invoke-vmscript.

Hence my confusion and not sure where to look at.

The tcpdump or network trace does indicate that the command is going outside the client machine to VCenter,. As you can see I was able to successfully execute this command for one ESXi cluster.

In my opinion, this may not be a bug with vMWare. Maybe an issue with configuration. I am trying to see what else I can do to identify the issue.

0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Did you try to run a test command as in my previous post? that would tell us if the command has been executed or not and where to look.

Anyway a part from the vmware.log file when you use the invoke-vmscript you can see some events in the vcenter ( select the VM, go to monitor and event ) like "Guest Operation..." so you can also check there. Also another test you can do is if the command copy-vmguestfile gives you a similar error or not. This command works very similar to invoke-vmscript for downloading or uploading files to the guest vm. Again you can see with a process monitor if the command is doing something or not.

Then last bit I would like to suggest is to you Lucd Invoke-VMScriptPlus that in verbose mode give you a better understing of what is going on and where the process fails.

Do all these try and let us know.

0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

Sorry. We took down the ESXi setup for general maintenance. Trying to bring it up. We will try as you suggested as soon as possible and share the results.

0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

Folks,

There was a firewall issue between our primary site and secondary one. After fixing those issues, we are able to invoke the script successfully.

Thanks for all your help.

0 Kudos