If i use move-vm without specifying datastore (because on the first step the vm won't change of datastore) i've got this error :
PS C:\> move-vm -vm vm1 -Destination (get-cluster -Name NEWCLUS) -portgroup (get-vdswitch NEW-DVS | get-vdportgroup -name namevlan)
WARNING: PowerCLI scripts should not use the 'VirtualSwitch' property of VmwareVDPortgroup type. The property will be removed in a future release.
move-vm : 24/07/2020 16:04:53 Move-VM A specified parameter was not correct: RelocateSpec
At line:1 char:1
+ move-vm -vm vm1 -Destination (get-cluster -Name NEWCLUS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
move-vm working fine by adding -datastore (get-datastore -name vSAN) -storagePolicy $policy -diskstorageformat thin to the previous command.
For the move to the folder vm i tried your script. So the export part give me a listing.
But the import seems to only create the folder and not moving the vms? We already succeeded to recreate all folders, but not able to move vm at their locations.
By the way the version of powercli :
7.0.0.15939650 VMware.Vim
12.0.0.15939657 VMware.VimAutomation.Cis.Core
12.0.0.15939652 VMware.VimAutomation.Common
12.0.0.15939655 VMware.VimAutomation.Core
12.0.0.15939651 VMware.VimAutomation.Sdk
12.0.0.15940185 VMware.VimAutomation.Vds