VMware Cloud Community
StephenMoll
Expert
Expert
Jump to solution

Using PowerCLI to ensure CpuAffinityList is empty...

I have been asked to look into providing one of our software teams with details on some PowerCLI commands to do some specific things.

One of these was to ensure that the CpuAffinityList on VMs was empty.

In the WebClient I can clear the "Scheduling Affinity" field, as per the information from the :smileyinfo: help dialogue.

If I then do :

Get-VM -Name $VMName | Get-VMResourceConfiguration | select CpuAffinityList

I get nothing in return as expected, I just get a column header:

CpuAffinityList

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

If I do:

Get-VM -Name $VMName | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuAffinityList ''

The Webclient will now show the "Scheduling Affinity" field will now have a "0" in it. Which according to the help information would give the vCPU of the VM affinity to processor 0, whereas what I actual want is to have no specified affinity.

This would to be at odds with the online help.

How do I clear the CPU affinity list using PowerCLI?

I have tried:

get-vm -name $VMName | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuAffinityList ([string]::Empty)

That gave the same result.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I see, in that case try with an empty array

Get-VM -Name | Get-VMResourceConfiguration |

Set-VMResourceConfiguration -CpuAffinityList @()


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

View solution in original post

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Isn't the list cleared when you do

Get-VM -Name | Get-VMResourceConfiguration |

Set-VMResourceConfiguration -CpuAffinity NoAffinity


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Yes but we are trying to avoid the obsolete commands.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which obsolete command?


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Sorry  I meant parameter, "CpuAffinity"

H:\> get-vm -name $VMName | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuAffinity NoAffinity

WARNING: Parameter 'CpuAffinity' is obsolete. Parameter 'CpuAffinity' is obsolete. Please use 'CpuAffinityList' isntead.

WARNING: The 'CpuAffinity' parameter of 'Set-VmResourceConfiguration' cmdlet is deprecated. Use the 'CpuAffinityList' parameter inst

ead.

VM                   NumCpuShares    CpuSharesLevel  NumMemShares    MemSharesLevel

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

Dummy04              1000            Normal          320             Normal        

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I see, in that case try with an empty array

Get-VM -Name | Get-VMResourceConfiguration |

Set-VMResourceConfiguration -CpuAffinityList @()


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Bingo!

Thanks Luc.

Why don't the other methods work, where does the zero come from when specifying an empty string?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect the code behind the cmdlet parameter checks how many elements there are.

Check the difference between

@().Count

''.Count

But this is my assumption, I would need to see the code behind the cmdlet for that.


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

So a string always has at least one character in it? A null?

Something to be wary of none-the-less.

Interesting.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, an empty string is not a $null object.
The $null indicates the non-existance of an object, while an empty string is still an object, a string.


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

I don't think that is what I said. I asked if a string always has at least one character, hence ''.count being 1, and if this one character was a $null?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, there isn't one character in there.
The Count property should be considered as counting how many elements there are in an array.

For a scalar, which also has the Count property, it should be considered as an array with one element, albeit an empty string.


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Yes, I had just come back to say much the same thing after have a tinker with:

''.Count = 1

('').Count = 1

''.Length = 0

('','').Count = 2

($null).Count = 0

Thanks for that.

Don't you sleep?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sleeping is overrated :smileygrin:


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