1 2 Previous Next 20 Replies Latest reply on May 15, 2018 6:11 AM by ym2018

    Copy-VMGuestFile - Error while trying to copy file from host to VM

    ym2018 Novice

      I’m trying to use the following command to copy file from host to VM:

       

      Copy-VMGuestFile -Source "$TestFilePath" -Destination "$DestinationPath" -LocalToGuest -Force -VM $Machinename -GuestUser "$VMGuestUserID" -GuestPassword "$VMGuestPassword" -ToolsWaitSecs -10 -Verbose

       

      The problem is that I’m getting an error:

      > WARNING: The guest OS for the virtual machine 'TestVM' is unknown. The operation may fail. Copy-VMGuestFile :  Copy-VMGuestFile  The guest operations agent could not be contacted.

       

      After googling this error, in several posts, there was a recommendation to install VMWare tools. I did. But still copy file command is failing.

       

      Virtual machine is Microsoft Windows 10 (64-bit). Firewall is off. VMWare tools is installed.

      Powershell version 5.1.

        • 1. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Are the VMware Tools running in the guest OS?

          What does this return?

           

          Get-VM <YourVM> | Select -ExpandProperty Guest

          • 2. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
            ym2018 Novice

            Yes, VMWare Tools is installed in the guest OS.

             

            Get-VM <YourVM> | Select -ExpandProperty Guest, returned:

             

            State              IPAddress                OSFullName

            -----                ---------                      ----------

            Running        {172.10.10.66, fe...   Microsoft Windows 10 (64-bit)

            • 3. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Ok, that seems to be ok, and VMware Tools obviously discovered that the target is running the Windows 10 guest OS.

              Can you try this version, and show what is returned?

              Note I used splatting to improve readibility.

               

              $sCopy = @{

                Source = "$TestFilePath"

                Destination = "$DestinationPath"

                LocalToGuest = $true

                VM = $Machinename

                GuestUser = "$VMGuestUserID"

                GuestPassword = "$VMGuestPassword"

                Verbose = $true

              }

              Copy-VMGuestFile @sCopy

              • 4. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                ym2018 Novice

                I'm getting the same error:

                VERBOSE: 5/15/2018 9:40:34 AM Copy-VMGuestFile Started execution

                VERBOSE: Copying source file 'C:\Temp\test.txt' from host to destination 'C:\test\' on VM 'TestVM'.

                WARNING: The guest OS for the virtual machine 'TestVM' is unknown. The operation may fail.

                Copy-VMGuestFile : 5/15/2018 9:40:34 AM Copy-VMGuestFile                The guest operations agent could not be contacted.

                At C:\Automation Framework\RevertCleanSnapshot.ps1:52 char:1

                + Copy-VMGuestFile @sCopy

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

                    + CategoryInfo          : NotSpecified: (:) [Copy-VMGuestFile], GuestOperationsUnavailable

                    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DirectoryExistsInGuest_ViError,VMware.VimAutomation.ViCore.C

                   mdlets.Commands.CopyVMGuestFile

                • 5. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  Can you check the vmware.log file? Normally it contains additional info on interactions with the VMware Tools.

                  It's located in the VM's folder on the datastore.

                   

                  Some more things to try.

                  Did you power off/power on the VM after the installation of the VMware Tools?

                  Did you stop/start your PowerShell/PowerCLI session from which you run the cmdlet?

                   

                  And which PowerCLI version are you using?

                  • 6. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                    ym2018 Novice

                    Did you power off/power on the VM after the installation of the VMware Tools? Yes I did. I saved this state in a snapshot. My script revert to this snapshot before trying to copy the file.

                    Did you stop/start your PowerShell/PowerCLI session from which you run the cmdlet? Yes I did. I closed the PowerShell and re-opened it.

                    VMware PowerCLI 10.0.0 build 7895300.

                    • 7. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      That leaves the vmware.log to check.

                      • 8. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                        ym2018 Novice

                        This is part of the log file. I'm not sure what to look for...

                         

                        2018-05-15T10:56:12.194Z| vcpu-2| I120: HBACommon: First write on scsi0:0.fileName='/vmfs/volumes/574ef75b-ec725889-f36b-2047479865ee/TestVM/TestVM-000001.vmdk'

                        2018-05-15T10:56:12.194Z| vcpu-2| I120: DDB: "longContentID" = "2cd7ba3357f17a95d74c60c8fd1ff90b" (was "5d7b432d1d4c8bd075aa38c95f55ed5e")

                        2018-05-15T10:56:12.199Z| vcpu-2| I120: DISKLIB-CHAIN : DiskChainUpdateContentID: old=0x5f55ed5e, new=0xfd1ff90b (2cd7ba3357f17a95d74c60c8fd1ff90b)

                        2018-05-15T10:56:22.153Z| vmx| I120: MainMem: Completed pending lazy prefault.

                        2018-05-15T10:56:22.195Z| vcpu-6| W110: GuestRpc: application toolbox-dnd, changing channel 65535 -> 2

                        2018-05-15T10:56:22.195Z| vcpu-6| I120: GuestRpc: Channel 2, guest application toolbox-dnd.

                        2018-05-15T10:56:22.195Z| vcpu-3| W110: GuestRpc: application toolbox, changing channel 65535 -> 0

                        2018-05-15T10:56:22.195Z| vcpu-3| I120: GuestRpc: Channel 0, guest application toolbox.

                        2018-05-15T10:56:24.041Z| vcpu-1| I120: TOOLS autoupgrade protocol version 2

                        2018-05-15T10:56:24.042Z| vcpu-1| I120: TOOLS Received tools.set.version rpc call, version = 10246.

                        2018-05-15T10:56:24.042Z| vcpu-1| I120: ToolsSetVersionWork did nothing; new tools version (10246) matches old Tools version

                        2018-05-15T10:56:24.046Z| vcpu-1| I120: Starting copy guest manifest.

                        2018-05-15T10:56:24.085Z| vcpu-2| I120: HGFileCopyCreateSessionCB: Successfully created the session.

                        2018-05-15T10:56:24.090Z| vcpu-2| I120: ToolsLoadManifestFileCB: Queuing a request to update the manifest information.

                        2018-05-15T10:56:24.103Z| Worker#0| I120: GetHostManifests: Extracting the manifest file.

                        2018-05-15T10:56:24.105Z| Worker#0| I120: GetHostManifests: Done extracting the manifest file.

                        2018-05-15T10:56:24.109Z| Worker#0| I120: ToolsVersionGetStatusWorkerThread: Tools status 3 derived from environment

                        2018-05-15T10:56:24.109Z| vmx| I120: ToolsUpdateManifestInfoWorkerThreadDone: Compared tools manifest from host and from the guest. Status = 3.

                        2018-05-15T10:56:24.109Z| vmx| I120: ToolsUpdateManifestInfoWorkerThreadDone: Updating the manifest info.

                        2018-05-15T10:56:24.109Z| vmx| I120: VMXVmdb_SetToolsVersionStatus: status value set to 'ok', 'current', install possible

                        2018-05-15T10:56:24.109Z| vmx| I120: TOOLS installed legacy version 10246, available legacy version 9541

                        2018-05-15T10:56:24.109Z| vmx| I120: TOOLS manifest update status is 3

                        2018-05-15T10:56:24.110Z| vmx| I120: TOOLS can be autoupgraded.

                        2018-05-15T10:56:24.110Z| vmx| I120: TOOLS Setting autoupgrade-checked TRUE.

                        2018-05-15T10:56:24.110Z| vmx| I120: RPT: Disabled. Skipped.

                        2018-05-15T10:56:28.528Z| vcpu-1| I120: TOOLS state change 4 returned status 1

                        2018-05-15T10:56:28.528Z| vcpu-1| I120: Vix: [4148225 mainDispatch.c:4210]: VMAutomationReportPowerStateChange: Reporting power state change (opcode=2, err=0).

                        • 9. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                          LucD Guru
                          vExpertCommunity WarriorsUser Moderators

                          Nothing obviously wrong in there, everything looks ok.

                           

                          The only strange entry in there is: TOOLS installed legacy version 10246, available legacy version 9541

                          Is that VM perhaps configured with a HW version that does not correspond with the ESXi version on which the VM is running?
                          Or is the VM running on an ESXi version that does not officially support Windows 10?

                           

                          On the power off/power on of the VM, to make sure did you do that on the VM level, and not on the guest OS level?

                          Is that VM in a cluster?

                          If yes, can you vMotion it to another ESXi node in the cluster?

                           

                          Something drastic you could eventually try:

                          • uninstall the VMware Tools in the guest OS
                          • reboot the guest OS
                          • install the VMware Tools
                          • reboot the guest OS
                          • try the Copy again
                          • 10. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                            ym2018 Novice

                            I have some progress -

                            As i mentioned before, my script revert to a clean snapshot (VMWare tools is installed on the clean snapshot) and then tries to copy a file to the VM.

                            My script calls the following command:

                            1. Connect-VIServer $VIserver -User $vCenterUser -Password $vCenterPass -WarningAction SilentlyContinue

                            2. Get-Snapshot -VM $VMName -Name $Snapname

                            3. Copy-VMGuestFile -Source "$Source" -Destination "$Destination" -LocalToGuest -Force -VM $Machinename -GuestUser "$VMGuestUserID" -GuestPassword "$VMGuestPassword" -ToolsWaitSecs -10 -Verbose

                             

                            When I run the script, it failes (with the error mentioned before).

                            But, if  I run the script, without calling Get-Snapshot command, it succeeds to copy the file.

                             

                            Do you have any ideas why calling Get-Snapshot, causes the copy to fail?

                            • 11. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                              LucD Guru
                              vExpertCommunity WarriorsUser Moderators

                              There are a couple of confusing points now.

                              • you stated earlier that your script reverts to the snapshot before doing the Copy-VMGuestFile
                              • that would explain the "First write on scsi0:0.fileName='/vmfs/volumes/574ef75b-ec725889-f36b-2047479865ee/TestVM/TestVM-000001.vmdk'" entry in the log
                              • a Get-Snapshot does not revert to a snapshot, it just obtains the info about a snapshot
                              • how do you actually revert to the snapshot? That would require a Set-VM cmdlet with the VM and Snapshot parameters.
                              • Do you make sure the revert to snapshot is complete before tackling the Copy-VMGuestFile? For example, do you check that the VMware Tools are running?

                               

                              At this stage I'm wondering if you can show us the actual script you are using, and not the condensed information you have been providing till now.

                              • 12. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                                ym2018 Novice

                                My mistake, I forgot a step. after calling Get-Snapshot, I'm calling:

                                Set-VM -VM $VMName -Snapshot $snapshot  -Confirm:$false

                                • 13. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                                  LucD Guru
                                  User ModeratorsvExpertCommunity Warriors

                                  I would still like to see the complete script you are using?

                                  • 14. Re: Copy-VMGuestFile - Error while trying to copy file from host to VM
                                    ym2018 Novice

                                    #connect VIserver:

                                    Write-Host " Connecting to your server $VIserver"

                                    $con = Connect-VIServer $VIserver -User $vCenterUser -Password $vCenterPass -WarningAction SilentlyContinue

                                     

                                    $snapshot = Get-Snapshot -VM $VMName -Name $Snapname

                                    Write-Host " Get the snapshot object to revert"

                                    if ($snapshot -ne $null) {

                                        $snap1 = Set-VM -VM $VMName -Snapshot $snapshot  -Confirm:$false

                                        if ($snap1 -ne $null){

                                            Write-Host "Snapshot reverted to "  $Snapname

                                        }

                                        else

                                        {

                                            Write-Host "Snapshot is not reverted " -ForegroundColor Red

                                        }

                                    }

                                    Else {

                                    Write-Host " Snapshot name given does not exist " -ForegroundColor Red

                                    }

                                     

                                    ########################Code to copy script to VM #########################

                                    Write-Host "Copying in process.....Data trasfering from $Source to $Destination " -ForegroundColor Green 

                                    -10 -Verbose

                                    $sCopy = @{

                                      Source = "$Source"

                                      Destination = "$Destination"

                                      LocalToGuest = $true

                                      VM = $Machinename

                                      GuestUser = "$VMGuestUserID"

                                      GuestPassword = "$VMGuestPassword"

                                      Verbose = $true

                                    }

                                     

                                    Copy-VMGuestFile @sCopy

                                    1 2 Previous Next