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?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Reply
0 Kudos
27 Replies
LucD
Leadership
Leadership
Jump to solution

Can you check if the vmware.log (found in the VM's folder) contains anymore clues?

You can also try to restart the VMware Tools inside the guest OS.

Any FW rules active inside the guest OS that might block?


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

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Thanks LucD for your reply.

Unfortunately the vmware.log doesn't contain any relevant logs, from what I can see in there everything is working correctly.

In fact the script has been processed correctly inside the guest OS but the Invoke-VMScript is not able to retrieve the result.

The firewall in the guest OS shouldn't matter because the Invoke-VMScript doesn't use the guest OS network to do the job that by the way is about configuring the network itself.
Also if I run the invoke-vmscript against the physical host instead of the vcenter server, it works so the problem shouldn't be related to the guest OS at all.
The guest OS anyway has been restarted many times and re-deployed too and the problem is affecting all the VMs

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you disable the DepreciationWarnings?


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

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Did that too, same result.

In fact, as you can see from my original post is not a deprecated warning message but an actual error.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, I saw the error from the Invoke-VMScript cmdlet, but I meant any depreciation messages from cmdlets inside the script you are running in the guest OS.
That's why you should place this as the 1st line in the script you run in the VM.

Can you check if there is anything in the log files in /var/log/vmware-vmsvc.log?

And is there a file in the directory in /tmp/vmware-<your username>*?


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

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Sorry, I didn't understand about the deprecation warning..

Anyway the script I am running using the Invoke-VMScript cmdlet is a simple "netsh interface ip set address `"Ethernet0`" static $($IP) $($NETMASK) $($GW)"

but can be a "ping" or a "dir". All command run correctly but same error when the Invoke-VMScript cmdlet try to get the result.

To notice that I have the same problem with Copy-VMGuestFile in both directions. If I try to copy a file from the guest VM to the local machine I can see the vmware-tools accessing and reading the file in the guest VM, the Copy-VmGuestFile create a empty file in my local machine and then I get the error.

and again if I run the command against the vmware physical host is working while if I run against the vcenter it doesn't. Vcenter, physical host and my machine are all in the same network.

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Forgot to say:

the vmware-vmsvc.log (vcenter) doesn't report anything and there is no /tmp/vmware-<username> directory

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just to clarify, the Invoke-VMScript works when connected to the ESXi node, but not when connected to the vCenter?


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

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Yes, exactly.

I got a vcenter with three ESXi node and vmware vpshere 6 standard license.

Everything installed from scratch with the following versions:

vcenter version: 6.7.0, 11727113

esxi host version: 6.7.0, 10764712

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is the PSC embedded or standalone?


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are not the only one experiencing this it seems.

See Error running Invoke-Vmscript - An error occurred while sending the request. FullyQualifiedErrorId :...


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

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

The PSC is embedded

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Interesting I looked everywhere and I didn't find anybody expect a guy but the thread didn't go nowhere

Reply
0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

I ran into the same issue. I have two ESXI clusters managed by one vCenter. I connected to vcenter using powercil.

One interesting thing is, I was able to invoke the script on one of the VM hosted on one cluster but not the other. No help from VMware logs.

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

If you check the link in the answer marked as "correct" you will find what cause the problem for me and somebody else.

Essentially, when the invoke-vmscript has to download the result, despite you are connected to the vcenter ,it is trying to connect to the ESX host using the IP address (not the FQDN) and in my case was failing because the certificate doesn't contain the ip address in the subject alternative name.

So I got two options: re-issue the certificate including the FQDN or disable the check of the certificate. You can find the workaround in the other thread.

Reply
0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

Thank you for your response. If it is the issue with certificate and the getting the output to the caller of the invoke script, then why I don't see any activity in the VMWare logs? We should have something logged there, isn't it?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Why would you expect something in any of the VMware logs?

The ESXi node just passes the certificate along.

When the caller (your script) can't verify that certificate with the CA, the problem is encountered on the client side.

You can try to do the following to one of the ESXi nodes that demonstrates the error.
You should get a message saying something along the lines of "Could not establish trust relationship for the SSL/TLS secure channel."

Invoke-WebRequest -Method Get -Uri https://ESXi-node-FQDN

When you do the same from PowerShell v6, the message is clearer.

It says "The remote certificate is invalid according to the validation procedure."

And in v6 you have the option SkipCertificateCheck, which will make the call work.

Invoke-WebRequest -Method Get -Uri https://ESXi-node-FQDN -SkipCertificateCheck


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

Reply
0 Kudos
vijaysaiv
Contributor
Contributor
Jump to solution

LucD

I may be missing some thing here. The solution says that we have an issue while downloading the results, which means the command should have got executed by then, so I expect that there must be some activity in the VMWare logs on the guest machine. Isnt it?

Reply
0 Kudos
gmslsupport
Enthusiast
Enthusiast
Jump to solution

Sorry but you said in your previous comment that you run into the same issue so I guess Lucd was explaining you that the log doesn't matter....

Also I think to see something in the log about the execution of the invoke-vmscript you have to enable some more verbose level.

Now, here the question:

Despite the error you got, does your command being executed? If you run something like "echo hello >c:\temp\test.txt does it work?

If not you probably have a different problem that need to be investigate.

Reply
0 Kudos