VMware Cloud Community
CaryTompkins_DS
Contributor
Contributor
Jump to solution

PowerCLI no longer moving VM to folder **UPDATED**

After further searching, I found this discussion answered by LucD.  (Move-VM doesn't work against new VCSA 6.7 instance )  His solution of using the current host as the destination host has resolved the errors.  Updated code directly below:

foreach ($server in $servers){

    $vm = Get-VM | Where-Object {$_.name -contains "$($server).dr"}

    $vmhost = $vm | get-vmhost

    Move-VM -VM $vm -Destination $vmhost -InventoryLocation $clientfolder

}

For the last couple months I have used a simple script to move VMs to different folders inside of vCenter and it has worked perfectly.  We recently upgraded our vCenter to 6.7 (Build 15129973) and now for some reason it errors against a random datastore in the environment.  My version of PowerCLI is 11.5.0 build 14912921, so I don't believe it is tied to the previous PowerCLI issues specific to build 6.7.  Below is my code and the new error:

$servers = Get-Content ".\input\client.txt"

$vcenter = "vcenter.domain.com"

$creds = get-credential -Message "Enter vCenter Credentials"

$connection = Connect-VIServer $vcenter -Credential $creds

$windowsfolder = Get-Folder -Type VM -Name Windows

$clientfolder = $windowsfolder | Get-Folder -Type VM -Name client

foreach ($server in $servers){

    $vm = Get-VM | Where-Object {$_.name -contains "$($server).dr"}

    Move-VM -VM $vm -InventoryLocation $clientfolder

}

$connection = Disconnect-VIServer -Confirm:$false -Force

The error that is now returning for all move attempts is:

Move-VM : 2/19/2020 1:40:33 PM  Move-VM         The operation for the entity "server.DR" failed with the following message: "Unable to access the virtual machine configuration:

Unable to access file [Datastore1]"

At line:4 char:5

+     Move-VM -VM $vm -InventoryLocation $clientfolder

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

    + CategoryInfo          : NotSpecified: (:) [Move-VM], CannotAccessVmConfig

    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you try changing

Move-VM -VM $vm -InventoryLocation $clientfolder

into

Move-VM -VM $vm -Destination $vm.VMHost -InventoryLocation $clientfolder


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Can you try changing

Move-VM -VM $vm -InventoryLocation $clientfolder

into

Move-VM -VM $vm -Destination $vm.VMHost -InventoryLocation $clientfolder


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
CaryTompkins_DS
Contributor
Contributor
Jump to solution

This is much more concise than my solution.  Thank you as always for your help!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This is an 'issue' (at least for me).
This is different behaviour than in previous PowerCLI versions.

Might be worth to raise an SR, with the idea 'The more report it ...'.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos