VMware Cloud Community
xacolabril
Expert
Expert
Jump to solution

How can I increase vCPUs via Powershell?

Good afternoon,

I want to make a PowerCLI script that allow me to increase/decrease vCPUS:

1) Stopping VM.

2) Increase or decrease vCPUs.

3) Starting VM.

Can you help me in this script?

Thank you in advance.

Best regards.






-----

VMware Certified Professional VCP3 and VCP4.

If you find this or any other information helpful or correct, please consider awarding points.

Xavier Colomé Abril. VMware Certified Professional VCP3, VCP4 and VCP5. [Si encuentras que esta o cualquier otra respuesta ha sido de utilidad, vótalas. Gracias.] [If you find this or any other information helpful or correct, please consider awarding points. Thank you.]
Tags (3)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Since I'm not sure if you want to create a function for this I provided a sample script to increase the vCPU number by 1.

$vm = Get-VM <VM-name>
$vm | Stop-VM -Confirm:$false
$vm | Set-VM -NumCpu ($vm.NumCpu + 1) -Confirm:$false
$vm | Start-VM -Confirm:$false

Perhaps there should also be some logic to test if the total number of vCPU is correct (1,2,3 or 4)

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Since I'm not sure if you want to create a function for this I provided a sample script to increase the vCPU number by 1.

$vm = Get-VM <VM-name>
$vm | Stop-VM -Confirm:$false
$vm | Set-VM -NumCpu ($vm.NumCpu + 1) -Confirm:$false
$vm | Start-VM -Confirm:$false

Perhaps there should also be some logic to test if the total number of vCPU is correct (1,2,3 or 4)

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

xacolabril
Expert
Expert
Jump to solution

Thank you LucD. I just reading another post writed for you:

http://communities.vmware.com/message/1339759#1339759

Thank you!






----


VMware Certified Professional VCP3 and VCP4.

If you find this or any other information helpful or correct, please consider awarding points.

Xavier Colomé Abril. VMware Certified Professional VCP3, VCP4 and VCP5. [Si encuentras que esta o cualquier otra respuesta ha sido de utilidad, vótalas. Gracias.] [If you find this or any other information helpful or correct, please consider awarding points. Thank you.]
0 Kudos
esxi1979
Expert
Expert
Jump to solution

Hi

0 Kudos
esxi1979
Expert
Expert
Jump to solution

my try so far is

$VMs = @("VM1","VM2","VM3")

$mem= @("mem1","mem2","mem3")

$cpu....

ForEach ($VM in $VMs)

   

    {

    Get-VM $VM |Set-VM -StaticMemory -MemoryStartupBytes $mem

    Get-VM $VM |Set-VM -NumCpu ($vm.NumCpu - $cpu) -Confirm:$false

    }

I am sure uw ill have a better one

0 Kudos