To troubleshoot this issue:
- 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.