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
This now is basically an issue with Invoke-WebRequest not working, nothing to do with PowerCLI nor the vSphere version.
Some other steps you might try:
- disable the FW on the station where you run the script
- disable the AV on the station where you run the script
Another possible cause, is the ESXi node behind a Proxy?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is port 443, or just https is enough.
So you are behind a Proxy (between the station where you run the script and the ESXi node)?
If the Proxy is the cause of the issue with the Copy-VMGuestFile cmdlet, you might want to check your PowerCLI configuration.
What is set for ProxyPolicy? Is that UseSystemProxy?
If not try setting that with Set-PowerCLIConfiguration.
If that doesn't work, you could try setting the Proxy address via the default parameter variable for Invoke-WebRequest.
Before calling the Invoke-VMScriptPlus function do the following (fill in your Proxy URI)
$PSDefaultParameterValues["Disabled"] = $False
$PSDefaultParameterValues=@{"Invoke-WebRequest:Proxy"="http://proxy-fqdn"}
If you Proxy requires credentials, you will also need to do this.
Make sure $proxyCred contains a PSCredential object with the Proxy credentials.
$PSDefaultParameterValues=@{"Invoke-WebRequest:ProxyCredential"=$proxyCred}
This will of course only fix Invoke-VMSCriptPlus and not Copy-VMGuestFile.
But at least we know where the issue comes from.
The only solution for the latter I can think of is to set the Proxy as the system default.
And then make sure PowerCLICOnfiguration is set to UseSystemProxy.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How do i remove or reset the proxy setting you shared?
Since i need to revert it as it was earlier ,before i use it.
Also i noticed the copy-vmguestfile and invoke-vmscript/plus works from the source to destination when port 443 from the source to the destination esxi host where the vm is hosted is opened.
Thanks
Bikash
Now you got me confused, so it appears that the whole problem was to 443 to ESXi not being open?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is what i suspect. which i happened to learn before i sent you the last message.
As i test multiple servers and the source VM from where the invoke-vmscript/copy-vmguestfile to the esxi host where the destination vm was hosted , the telnet to that esxi node over 443 from the source vm was not working.
And for the working invoke-vmscript/copy-vmguestfile the telnet to port 443 to the esxi node of the destination VM was working.
And the confusing part was when i used the proxy to open the esxi fqdn on the browser it opened but the telnet was still not working. But when the proxy was disabled on the browser the fqdn of the esxi was not working on the browser & telnet is not working on either case.
So it is mandotory/required to have the port 443 opened to the destination vm esxi node for which we will run the invoke-vmscript/copy-vmguestfile from the source VM. That is what i assume.
Yes, as you noticed transferring files to/from the VM happens through a URI on the ESXi node that hosts the targetted VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc for helping me throughout this. Happy Weekend!!!!