2

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

Uh Trog
  • 103
  • 3
  • 10

1 Answers1

3

According to the documentation, the -Location parameter for New-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 to New-VM.

You can refine the results of Get-Folder by piping a Datacenter, VM or Cluster to it, or by piping it to Where-Object and checking the Parent 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:

New-VM -Name $VMdest -VM $VMorig -VMHost $ESXhost -Datastore $ds -Location (Get-Folder -ID (Get-VM $VMorig).FolderId) -DiskStorageFormat thin -RunAsync
GregL
  • 9,370
  • 2
  • 25
  • 36
  • Hi, Thanks a lot it works. But reading this documentation was not enough clear that Folder should be an object. I was doing some testing using unique names in plain text, and it also worked, this is why i was trying to use string names in the folder parameter. – Uh Trog Jul 28 '15 at 09:33