PowerShell Friday: Adding CPU’s with PowerCLI
Sometimes you need to add CPUs to your virtual machines. Adding CPU’s is easy on a virtual machine. Of course you can do this from the vSphere Client, where you can select the number of CPUs and the number of cores per CPU. If you only need to change one virtual machine this isn’t a problem. When you have to change 50 virtual machines it gets somewhat tiresome.
Luckily we can use PowerCLI for that. With the cmdlet Set-VM you can change all kinds of parameters of the virtual machine. The command below gets a VM object and changes the number of CPUs.
get-VM -name MyVM | set-VM -NumCpu 2
sets the number of CPU’s for this VM to two. It asks you if you’re sure.
Confirmation Proceed to configure the following parameters of the virtual machine with name 'dc01'? New NumCpu: 2 [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
This way you add 2 CPU’s (sockets) to the virtual machine with each one core. If you want to add CPU’s with multiple cores you need to do something extra.
$VM=Get-VM -Name MyVM $VMSpec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{“NumCoresPerSocket” = 2} $VM.ExtensionData.ReconfigVM_Task($VMSpec) $VM | Set-VM -NumCPU 2
Make sure that NumCPU is the total number of cores you want. If you want 2 CPU’s with 2 cores you set NumCPU to 4.
Removing the CPU’s
Of course you can also remove the CPU’s again from the virtual machine. You just set the number to a lower quantity. If you need to reduce the core count, use the $VMSpec part above with NumCoresPerSocket set to 1.
get-VM -name MyVM | set-VM -NumCpu 1
Other articles in the series PowerShell Friday:
- PowerShell Friday: Getting Started with PowerShell and PowerCLI
- PowerShell Friday: Connecting to vCenter
- PowerShell Friday: Starting VMs
- PowerShell Friday: stopping VMs
- PowerShell Friday: Creating Virtual Machines
- PowerShell Friday: Snapshots
- PowerShell Friday: Adding CPU’s with PowerCLI
- PowerShell Friday: Adding Memory with PowerCLI
- PowerShell Friday: ExtensionData
- PowerShell Friday: Retrieving IP addresses for VMs
- PowerShell Friday: Copying files with Copy-VMGuestFile
- PowerShell Friday: Setting Reservations with PowerCLI
- PowerShell Friday: Enabling SSH with PowerCLI
- PowerShell Friday: Christmas Special
- PowerShell Friday: Configuring vSphere MTU Size
- PowerShell Friday: Load PowerCLI from your own script
- PowerShell Friday: Using the Cisco ACI API
Related Posts:
- Onboard existing workloads in Cloud Automation Services by Erik Scholten
- Getting started with Photon OS by Anne Jan Elsinga
- Using VMware and Veeam? Update VBR 9.5 to Update 3a now by Edwin Weijdema
- Using input parameters to create dynamic blueprint… by Anne Jan Elsinga
- How to install HyTrust KeyControl 5.1 in vSphere 6.7 by Edwin Weijdema
Anne Jan Elsinga
Related Posts
Leave a Reply Cancel reply
You must be logged in to post a comment.