VMware Cloud Community
MandeepJ
Enthusiast
Enthusiast
Jump to solution

Move a list of VMs to different folder (Blue)

Hello Experts,

I have a situation where i need to change folder location for couple of VMs, i tried using below script but after importing it seems get-folder command is unable to get content of csv. I am getting error as null or value not found with both columns i.e. vmname & folderid. Is this something related to vCenter version? Any idea how to correct this?

$vmlist = import-csv vm_placement.csv

$vmlist | % {

$folder = Get-Folder -id $vmlist.folderid

Move-VM -VM $vmlist.vmname -destination $folder

}

Thanks

Mandeep

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this, you should refer to the pipeline variable inside the loop.

$vmlist = import-csv vm_placement.csv

$vmlist | % {

    $folder = Get-Folder -id $_.folderid

    Move-VM -VM $_.vmname -destination $folder

}


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

View solution in original post

3 Replies
MandeepJ
Enthusiast
Enthusiast
Jump to solution

I just checked, its picking up if i put single VM in that CSV. any idea whats wrong?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this, you should refer to the pipeline variable inside the loop.

$vmlist = import-csv vm_placement.csv

$vmlist | % {

    $folder = Get-Folder -id $_.folderid

    Move-VM -VM $_.vmname -destination $folder

}


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

MandeepJ
Enthusiast
Enthusiast
Jump to solution

Thanks Luc!

Reply
0 Kudos