I'm trying to clone some Virtual Machines using POWERCLI, but when I set the target location I'll have the error "Could not find Folder with name" …
My folder estructure is like:
DC1\destfolder
DC2\destfolder
Where destination folder name is the same on each DCenter.
I'm using the following command
New-VM -Name $VMdest -VM $VMorig -VMHost $ESXhost -Datastore $ds -Location $destFolder -DiskStorageFormat thin -RunAsync
On $destfolder variable I've set providing full path, like "dc1\destfolder" or "dc1\vm\destfolder" but in both cases I allways have the error "Could not find Folder"
I've also tried to use the Folder ID, but "location" parameter doesn't recognize it because it uses the name.
Any Idea?
Regards
Best Answer
According to the documentation, the
-Location
parameter forNew-VM
expects an object of type Folder.If you're passing in a path string, then it's not going to work.
You'd need to use Get-Folder, with either the folder ID (
Get-Folder -ID Folder-group-v30070
), or the name of the folder itself (Get-Folder destfolder
) to store the Folder object and then pass that along toNew-VM
.You can refine the results of
Get-Folder
by piping a Datacenter, VM or Cluster to it, or by piping it toWhere-Object
and checking theParent
property to see if it's what you expect.If you're clonning a VM and want to place the clone in the same folder as the source, then you can do something like: