VMware Cloud Community
Werdo00
Enthusiast
Enthusiast

powercli command to add cpu cores to the cpu?

i know that the command for add cpu is -NumCpu  ... but whats the command to add x numbers of cores to the cpu?

Thanks for your help

11 Replies
LucD
Leadership
Leadership

No cmdlet afaik, but you can use the SDK method ReconfigVM.

Something like this

$spec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{“NumCoresPerSocket” = 1}

(Get-VM –Name Test_VM).ExtensionData.ReconfigVM_Task($spec)


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

cwriordan
Contributor
Contributor

to avoid GUI warnings when editting a VM's settings...

$spec = new-object -typename VMware.VIM.virtualmachineconfigspec -property @{'numcorespersocket'=$corecount;'numCPUs'=$($proccount * $corecount)}

where proccount and corecount are variables containing the number of procs and cores you want

0 Kudos
adibax
Enthusiast
Enthusiast

Hello guys,

I script on powercli to create VM and at the end of my script  I use method above for set the number of core (why there isn't a parameter on 'New-VM' ?????? F****)

I test the first solution who works but I got a warning when I check the settings with vsphere so I test the second solution for bearing the warning but doesn't works ! cpu x cprcore ??? I dont understand what do you mean OmniWig ?!

Focus on the first solution who works well.

When I press OK the number of CPU and CPUCORE are good but why this warning appears ???

Thank you all

ErrorSettingsCoreCpu.jpg

FYI :

The end of my script

enofscript.jpg

0 Kudos
LucD
Leadership
Leadership

Try like this

$proccount = 8

$corecount = 4

$spec = new-object -typename VMware.VIM.virtualmachineconfigspec -property @{'numcorespersocket'=$corecount;'numCPUs'=$proccount}

(Get-VM –Name TestVM).ExtensionData.ReconfigVM_Task($spec)

This will assign 2 vCPU with each 4 cores


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

adibax
Enthusiast
Enthusiast


OK thank you for your answer LucD Smiley Wink

But if I want 1 socket and 2 cores ? I have to enter this :

$proccount=2

$corecount=2

I dont understand the logic !?!? Could you explain to me please ?

Thank you in advance for your precious time  Smiley Wink

0 Kudos
LucD
Leadership
Leadership

That  is correct.

The explanation is in the 2 properties in the VirtualMachineConfigSpec object.

cpu-cores.png

The numCPU is the total number of cores in the VM.

The numCoresPerSocket states how many cores there will be in a vCPU.

Some examples:

numCPU = 8

numCoresPerSocket = 4

will result in 2 virtual socket, each with 4 cores

numCPU = 2

numCoresPerSocket = 2

will result in 1 virtual socket with 2 cores


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

adibax
Enthusiast
Enthusiast


It's Perfect Smiley Wink

Thank you very very much LucD :smileygrin:

Best Regards

0 Kudos
cypherx
Hot Shot
Hot Shot

How did you get this to work?  I tried running this in a power shell script and got an error.

At the top I just added:

Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer vcenterserverFQDN

New-Object : Member "numcorespersocket" not found for the given .NET object.

At C:\scripts\web1.ps1:7 char:19

+ $spec = new-object <<<<  -typename VMware.VIM.virtualmachineconfigspec -prope

rty @{'numcorespersocket'=$corecount;'numCPUs'=$proccount}

    + CategoryInfo          : InvalidOperation: (:) [New-Object], InvalidOpera

   tionException

    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C

   ommands.NewObjectCommand

Type  : Task

Value : task-37849

0 Kudos
adibax
Enthusiast
Enthusiast

Work well for me Smiley Wink

Capture.PNG

0 Kudos
samjbentley
Contributor
Contributor

I'm seeing errors thrown when I run this script on PowerCLI 6 R3. Any ideas? I'm not sure I have an older environment to try running the code on, I suspect you're all running 5.5 or earlier?

TestVM is an existing VM that I've manually created in the GUI for testing, after which I'll further flesh out my code.

$proccount = 8

$corecount = 4

$spec = new-object -typename VMware.VIM.virtualmachineconfigspec -property @{'numcorespersocket'=$corecount;'numCPUs'=$proccount}

(Get-VM –Name TestVM).ExtensionData.ReconfigVM_Task($spec)

PowerCLI C:\Users\maskeduser\Desktop> .\TestSpec.ps1

At C:\Users\maskeduser\Desktop\TestSpec.ps1:11 char:24

+ (Get-VM â?"Name "TestVM").ExtensionData.ReconfigVM_Task($spec)

+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The string is missing the terminator: ".

At C:\Users\maskeduser\Desktop\TestSpec.ps1:11 char:63

+ (Get-VM â?"Name "TestVM").ExtensionData.ReconfigVM_Task($spec)

+                                                               ~

Missing closing ')' in expression.

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

0 Kudos
samjbentley
Contributor
Contributor

Ah, it doesn't like the -Name option, remove it.

$proccount = 8

$corecount = 4

$spec = new-object -typename VMware.VIM.virtualmachineconfigspec -property @{'numcorespersocket'=$corecount;'numCPUs'=$proccount}

(Get-VM TestVM1).ExtensionData.ReconfigVM_Task($spec)

0 Kudos