I need a script that will be fed by a CSV. Name, CPU, Socket will be the columns. The script needs to power down the VM's, set the socket count and cpu count and power on the VM's. Is there one out there?
Thanks,
Pete
You can incorporate that
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.CpuHotAddEnabled = $true # or $false
Import-Csv -Path .\data.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
Get-VM -Name $row.Name | Shutdown-VMGuest -Confirm:$false
while ((Get-VM -Name $row.Name).PowerState -ne 'poweredoff'){
sleep 5
}
$vm = Get-VM -Name $row.Name
$vm.ExtensionData.ReconfigVM($spec)
Set-VM -VM $vm -NumCpu $row.CPU -CoresPerSocket $row.Cores -Confirm:$false |
Start-VM -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean something like this?
Import-Csv -Path .\data.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
Get-VM -Name $row.Name | Shutdown-VMGuest -Confirm:$false
while ((Get-VM -Name $row.Name).PowerState -ne 'poweredoff'){
sleep 5
}
Get-VM -Name $row.Name | Set-VM -NumCpu $row.CPU -CoresPerSocket $row.Cores -Confirm:$false |
Start-VM -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
That worked perfectly. Is there a way to disable or enable cpu hot add for each iteration through the loop?
-Pete
You can incorporate that
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.CpuHotAddEnabled = $true # or $false
Import-Csv -Path .\data.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
Get-VM -Name $row.Name | Shutdown-VMGuest -Confirm:$false
while ((Get-VM -Name $row.Name).PowerState -ne 'poweredoff'){
sleep 5
}
$vm = Get-VM -Name $row.Name
$vm.ExtensionData.ReconfigVM($spec)
Set-VM -VM $vm -NumCpu $row.CPU -CoresPerSocket $row.Cores -Confirm:$false |
Start-VM -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked too! Thanks very much!