VMware Cloud Community
DevD
Enthusiast
Enthusiast
Jump to solution

Need to change core per Socket

Does anyone know the powercli to check the vCPU of a VM and change the Core per socket to match the vCPU.

pastedImage_0.pngpastedImage_1.png

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, try like this.
Remember, the VM needs to be powered off to change this setting.

Get-VM -Name TestVM | where { $_.NumCpu -ne $_.CoresPerSocket } |

ForEach-Object -Process {

   Set-VM -VM $_ -CoresPerSocket $_.NumCpu -Confirm:$false

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
10 Replies
daphnissov
Immortal
Immortal
Jump to solution

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes I do.


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this.
But be aware that this is not foo-proof.
You can't change the CoresPerSocket in all cases to NumCPU.

Get-VM -PipelineVariable vm | where{$_.NumCpu -ne $_.CoresPerSocket} |

Set-VM -CoresPerSocket $vm.NumCpu -Confirm:$false


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

0 Kudos
DevD
Enthusiast
Enthusiast
Jump to solution

Getting an error.

>Set-VM -PipelineVariable TEST1 | where{$_.NumCpu -ne $_.CoresPerSocket} |Set-VM -CoresPerSocket $vm.NumCpu -Confirm:$false

Set-VM : Cannot validate argument on parameter 'CoresPerSocket'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null

values and then try the command again.

At line:1 char:100

+ ... Cpu -ne $_.CoresPerSocket} |Set-VM -CoresPerSocket $vm.NumCpu -Confir ...

+                                                        ~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Set-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You changed the name of the PipelineVariable is used.
That's why you get the error.


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

0 Kudos
DevD
Enthusiast
Enthusiast
Jump to solution

Ohh i though that's the name of VM for which we want to change the config.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, if you want to test with a specific VM, you can use the Name parameter.

Get-VM -Name TestVM -PipelineVariable vm | where { $_.NumCpu -ne $_.CoresPerSocket } |

Set-VM -CoresPerSocket $vm.NumCpu -Confirm:$false


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

0 Kudos
DevD
Enthusiast
Enthusiast
Jump to solution

Tried this but still getting the error.

Get-VM -Name TEST1 -PipelineVariable vm | where { $_.NumCpu -ne $_.CoresPerSocket } |Set-VM -CoresPerSocket $vm.NumCpu -Confirm:$false

Set-VM : Cannot validate argument on parameter 'CoresPerSocket'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null

values and then try the command again.

At D:\Anoop\Scripts\Lab\Lab.ps1:3 char:24

+ Set-VM -CoresPerSocket $vm.NumCpu -Confirm:$false

+                        ~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Set-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, try like this.
Remember, the VM needs to be powered off to change this setting.

Get-VM -Name TestVM | where { $_.NumCpu -ne $_.CoresPerSocket } |

ForEach-Object -Process {

   Set-VM -VM $_ -CoresPerSocket $_.NumCpu -Confirm:$false

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

0 Kudos
DevD
Enthusiast
Enthusiast
Jump to solution

It worked, thank you for all your help !!

0 Kudos