VMware Cloud Community
Calmateur
Contributor
Contributor
Jump to solution

PowerCli Move Folder with full path or folderID

Hi,

I'm looking for a way to register a VM with a specific folder.

"New-VM  -Location $folder"

But it's working only if one folder existing with that name. I did a function to get the full path but it doesn't seem to accept it.

So i tried with "Move-VM" after the registration but it doesn't work neither.

New-vm or Move-Vm can accept fullpath folder or idfolder ?

Kind Regards

Reply
0 Kudos
1 Solution

Accepted Solutions
vXav
Expert
Expert
Jump to solution

You can do:

New-VM -VMFilePath "[$datastore] $vmname/$vmname.vmx" -Location (Get-folder -Id $folderID)

View solution in original post

Reply
0 Kudos
3 Replies
vXav
Expert
Expert
Jump to solution

You could use the name of the folder or the Folder object (from the get-folder cmdlet) if you have several folders with the same name (I believe this is what you are talking about?).

Reply
0 Kudos
Calmateur
Contributor
Contributor
Jump to solution

Hi,vXav

I'm not sure to follow you, for my example :

"New-VM -VMFilePath "[$datastore] $vmname/$vmname.vmx" -Location $folder"

If i don't put a simple name in $folder, my command doesn't work. I tried with a fullpath and folder id.

And like you guess, several folders have the same name.

Reply
0 Kudos
vXav
Expert
Expert
Jump to solution

You can do:

New-VM -VMFilePath "[$datastore] $vmname/$vmname.vmx" -Location (Get-folder -Id $folderID)

Reply
0 Kudos