PowerCLI script to rename Virtual machines from a CSV file
$csv=Import-CSV rename.csv
foreach($vm in $csv)
{
Get-VM $($vm.oldname) | Set-VM -name $($vm.newname) -confirm:$false
}
Rename.csv
oldname,newname
Win2008,WIN2008
winvm-test1,WINVM-TEST1
winvm-test2,WINVM-TEST2
winvm-test4,WINVM-TEST4
Output:
$csv=Import-CSV rename.csv
foreach($vm in $csv)
{
Get-VM $($vm.oldname) | Set-VM -name $($vm.newname) -confirm:$false
}
Rename.csv
oldname,newname
Win2008,WIN2008
winvm-test1,WINVM-TEST1
winvm-test2,WINVM-TEST2
winvm-test4,WINVM-TEST4
Output:
Name | PowerState | Num CPUs | MemoryGB |
---- | ---------- | -------- | -------- |
WIN2008 | PoweredOff | 1 | 2 |
WINVM-TEST1 | PoweredOff | 1 | 2 |
WINVM-TEST2 | PoweredOff | 1 | 2 |
WINVM-TEST4 | PoweredOff | 1 | 2 |
No comments:
Post a Comment