VMware Cloud Community
PeteHow
Enthusiast
Enthusiast
Jump to solution

Powercli Shut VM's Down Set CPU Set Socket Power On CSV

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

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

PeteHow
Enthusiast
Enthusiast
Jump to solution

Luc,

That worked perfectly.  Is there a way to disable or enable cpu hot add for each iteration through the loop?

-Pete

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

PeteHow
Enthusiast
Enthusiast
Jump to solution

That worked too!  Thanks very much!

0 Kudos