Hi there
I am looking for a bit of help to script the following senario.
I want to run a script on our production cluster to get a list of VMs and the Folder location in vCenter then export to a csv file.
then at our DR site i want to use that csv file to move the list of VMs to the correct folders.
I have the script below already
Move-VM -VM fileserver1 -Destination (Get-Folder -Name "File Servers")
but would need to have a line per VM that would constantly need updating.
any help much appreciated.
S
Assuming that all your folders are level 1 folder, in other words not nested folders, you can do the following to create a CSV file
Get-VM | select Name,@{N="Folder";E={$_.Folder.Name}} | `
Export-Csv "C:\vm-folder.csv" -NoTypeInformation -UseCulture
To move the VMs to the correct folder from this CSV file you could do
Import-Csv "C:\vm-folder.csv" -UseCulture | %{ Move-VM -VM $_.Name -Destination (Get-Folder -Name $_.Folder) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Assuming that all your folders are level 1 folder, in other words not nested folders, you can do the following to create a CSV file
Get-VM | select Name,@{N="Folder";E={$_.Folder.Name}} | `
Export-Csv "C:\vm-folder.csv" -NoTypeInformation -UseCulture
To move the VMs to the correct folder from this CSV file you could do
Import-Csv "C:\vm-folder.csv" -UseCulture | %{ Move-VM -VM $_.Name -Destination (Get-Folder -Name $_.Folder) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
the command you gave works perfectly even for nested folders as long as all folder names are unique.
many thanks
S
Muchas gracias, me sirvio mucho dicho codigo. Saludos.