PowerCLI

 View Only
Expand all | Collapse all

Copy-vmguestfile. An error occurred while sending the request

bikashyadav

bikashyadavJul 02, 2021 08:56 AM

  • 1.  Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 12:49 PM


    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



  • 2.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 02:32 PM

    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?



  • 3.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 02:48 PM

    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.



  • 4.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 06:08 PM

    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.



  • 5.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 06:18 PM

    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?



  • 6.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 06:48 PM

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



  • 7.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 07:03 PM

    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.

     



  • 8.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 01, 2021 08:40 PM

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



  • 9.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 06:44 AM

    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



  • 10.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 08:21 AM

    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.



  • 11.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 08:33 AM

    No its giving same error. Attached is the error.



  • 12.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 08:36 AM

    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.



  • 13.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 08:56 AM

    Attached is the error what i am getting Luc.



  • 14.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 09:22 AM

    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.



  • 15.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 09:41 AM

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

    Attached is the screenshot of the error.

     



  • 16.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 10:17 AM

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



  • 17.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 10:41 AM

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



  • 18.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 10:52 AM

    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
    

     



  • 19.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 11:08 AM

    Hi Luc,

     

    Attached is the error with the new code.

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



  • 20.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 11:26 AM

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



  • 21.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 11:55 AM

    Hi Luc,

    I can open the esxi fqdn on the browser when i use proxy, but the esxi fqdn doesnt opne when the proxy is removed from the broweser.

    ANd which port u are referring to use with the fqdn? 902? or 443?

    Attached is for ur reference.



  • 22.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 12:07 PM

    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.






  • 23.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 01:00 PM

    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



  • 24.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 02:35 PM

    Now you got me confused, so it appears that the whole problem was to 443 to ESXi not being open?



  • 25.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 03:01 PM

    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.



  • 26.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 03:03 PM

    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.

     



  • 27.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 03:04 PM

    Yes, as you noticed transferring files to/from the VM happens through a URI on the ESXi node that hosts the targetted VM.



  • 28.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 04:29 PM

    Thanks Luc for helping me throughout this. Happy Weekend!!!!



  • 29.  RE: Copy-vmguestfile. An error occurred while sending the request

    Posted Jul 02, 2021 11:44 AM

    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?