Running the Copy-VMGuestFile cmdlet on Windows Server 2012 fails with the error: Unable to access file
search cancel

Running the Copy-VMGuestFile cmdlet on Windows Server 2012 fails with the error: Unable to access file

book

Article ID: 341989

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

Symptoms:
  • Running the Copy-VMGuestFile cmdlet on Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, and Windows Server 2012 R2 fails.
  • You see the error:

    Unable to access file unspecified filename


Environment

VMware vSphere PowerCLI 5.0.1
VMware vSphere PowerCLI 5.0
VMware vSphere PowerCLI 5.5

Resolution

To troubleshoot this issue:
  1. Run this script to identify if the problem is with the API itself or in the configuration of the windows virtual machine:

    $vm = Get-VM "enterVMName"
    $file = Get-Item "c:\source.txt" #Create a text file and give the path where the
    file is located.
    $destination = "c:\destination.txt"
    $force = $false # e.g. overwrite any existing file with this name

    $auth = New-Object VMware.Vim.NamePasswordAuthentication
    $auth.interactiveSession = $false
    $auth.username = "enterusernamehere"
    $auth.password = "enterpasswordhere"

    $fileAttributes = New-Object VMware.Vim.GuestFileAttributes

    $guestFileManager = Get-View -Id 'GuestFileManager-guestOperationsFileManager'
    $uploadUrl = $guestFileManager.InitiateFileTransferToGuest($vm.Id, $auth, $destination, $fileAttributes, $file.Length, $force)

    $webClient = New-Object System.Net.WebClient
    $webClient.UploadFile($uploadUrl, "PUT", $file.FullName)

    Note: The script directly uses the vSphere API and uploads a single file from the local machine to a virtual machine.
If the problem still persists after running the preceding script, use one of these options to identify if the issue is with the Windows operating system.
  • Verify the user account control settings within the local security policy.
  • Verify permissions for the user account within the effected folder.
  • Add a user to the folder explicitly.


Additional Information

For more information, see: