VMware Cloud Community
bikashyadav
Contributor
Contributor

Copy-vmguestfile. An error occurred while sending the request


Source Server is SRV2
Destination Server is SRV1

when running Copy-VMGuestFile -Source "C:\Users\test\Documents\test.csv" -Destination "C:\tmp" -VM SRV1 -LocalToGuest -GuestCredential $cred

I get below error. But when my source server is SRV1 & destination is SRV2(Copy-VMGuestFile -Source "C:\Users\test\Documents\test.csv" -Destination "C:\tmp" -VM SRV2 -LocalToGuest -GuestCredential $cred),
runs perfectly and the file gets copied. Any leads or idea why its happening?

Copy-VMGuestFile : 7/1/2021 7:07:35 AM Copy-VMGuestFile An error occurred while sending the request.
At line:1 char:1
+ Copy-VMGuestFile -Source "C:\Users\test\Documents\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-VMGuestFile], ViError
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_UploadFileToGuest_UploadError,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyVMGuestFile

0 Kudos
28 Replies
LucD
Leadership
Leadership

So in one case you are running the script from SRV1 and copy to SRV2, and in the other you run the script on SRV2 and copy to SRV1?

Is port 902 open on both servers towards the respective ESXi nodes?


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

0 Kudos
bikashyadav
Contributor
Contributor

So in one case you are running the script from SRV1 and copy to SRV2, and in the other you run the script on SRV2 and copy to SRV1? Yes

Is port 902 open on both servers towards the respective ESXi nodes? No. SRV1 to SRV2 esxi node port 902 is opened but SRV2 to SRV1 esxi node port 902 is not opened when i used telnet to check.

But the esxi/vc are on 6.7 version so i guess port 902 is not mandatory and doesn't apply. And the weird part is for few servers 902 port is open towards the esxi node and copy is working but there are other servers where the port 902 is not opened towards the esxi node but still the copy is working. Not sure wat is the issue here. 

If you see the error screenshot. I copied the csv file to the destination location and run the code & In 1st attempt you will see it says file already exists, means its reaching to the destination server and fetching the info and since the file is already there it doesnt copy it.

But in 2nd attempt i deleted the file and re-run the same code and i got the actual error.

Not sure what could be the issue here. But the same code to the same destination from some other servers work fine.

0 Kudos
LucD
Leadership
Leadership

Afaik the port 902 requirement is not related to the vSphere version.

There is the warning that the VMware Tools are an older version.
Did you try upgrading those to the correct version?

You could run something like filemon, from the Sysinternals Suite, on the receiving server to check if the file is created.
Or at least if VMware Tools try to create the file.


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

0 Kudos
bikashyadav
Contributor
Contributor

i can try upgrading the tool version, but to the same server I can copy from some other server ,without any issue with the warning still showing. In some other set of server we tried updating the tools version but it didn't worked. 

I will try the filemon option. Any other suggestions Luc?

0 Kudos
LucD
Leadership
Leadership

Can you check if Invoke-VMScript works in both directions?


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

0 Kudos
bikashyadav
Contributor
Contributor

Invoke-VMscript only work 1 side where i can run the copy-vmguestfile cmdlet.

taking our 1st example Source server as SRV2 & Destination Server as SRV1.

SRV2 to SRV1 invoke-vmscript doesnt work neither the copy-vmguestfile. It gives the same error "An error occurred while sending the request"

But from SRV1 to SRV2 invoke-vmscript & copy-vmguestfile works fine.

 

0 Kudos
LucD
Leadership
Leadership

Can you try the same with my Invoke-VMScriptPlus with the Verbose option?
That might give more info on what the problem is.


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

0 Kudos
bikashyadav
Contributor
Contributor

HI Luc,

Attached is the error details with verbose switch in the not working set of server. Where the invoke-vmscript also doesnt work.

And below screenshot pasted is from the working set of server where invoke-vmscript/copy-vmguestfile is working but NOT sure why Invoke-vmscriptplus is giving some error.

bikashyadav_0-1625209430622.png

 

Thanks

Bikash

0 Kudos
LucD
Leadership
Leadership

Ok, that could explain what is happening.
Try using the NoIPInCert and/or SkipCertificateCheck switches on the Invoke-VMScriptPlus function, and check if that solves the issue.


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

0 Kudos
bikashyadav
Contributor
Contributor

No its giving same error. Attached is the error.

0 Kudos
LucD
Leadership
Leadership

That is not the same error.
Try stopping/starting your PS session.
That error is quite often an issue in the PS environment.

Keep the Verbose switch present, that will provide more info.


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

0 Kudos
bikashyadav
Contributor
Contributor

Attached is the error what i am getting Luc.

0 Kudos
LucD
Leadership
Leadership

That NameHost error is a typo that slipped into my code it seems.
I just posted a corrected version of the function, try with the latest version.


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

0 Kudos
bikashyadav
Contributor
Contributor

I used the latest code & now the error is different.

Attached is the screenshot of the error.

 

0 Kudos
LucD
Leadership
Leadership

Looks like I had another bug (type test) in there, should be corrected now.


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

0 Kudos
bikashyadav
Contributor
Contributor

Tried with the new code and the error what i am getting is attached.

0 Kudos
LucD
Leadership
Leadership

Ok, now we are getting somewhere.
The transfer of the code to target VM seems to fail for whatever reason.

Let's first check if the URI makes sense.
Can you add after line 239 (the one with Write-Verbose) a line with Format-Custom.
That should show the URI that is actually used.

      Write-Verbose -Message "Copying $($PSCmdlet.ParameterSetName) to $File"
      $sWeb | Format-Custom    # <-- add this line

 


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

0 Kudos
bikashyadav
Contributor
Contributor

Hi Luc,

 

Attached is the error with the new code.

The uri value is the esxi fqdn name where the destination VM is hosted.

0 Kudos
LucD
Leadership
Leadership

Can you connect to that FQDN with a web browser?
Just the FQDN and the port


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

0 Kudos