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
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
I just checked, its picking up if i put single VM in that CSV. any idea whats wrong?
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
Thanks Luc!
