VMware Cloud Community
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

vCloud Director - Change CPU "Number of sockets" and "Cores per socket" with PowerCLI

Hi all,

how can I change the  CPU "Number of sockets" and "Cores per socket"  in vCloud Director with PowerCLI?

vCloud Director version 10.3.3.19610595

PowerCLI version 12.7

 

I want to change

"Cores per socket" from 1 to 8 

"Number of sockets" from 8 to 1

 

RoyalFlash_0-1676288599400.png

 

0 Kudos
1 Solution

Accepted Solutions
Macleud
Enthusiast
Enthusiast
Jump to solution

Hi.

I'm not sure if it can be done (CoresPerSocet) via PowerCli.
Try using Powershell API.
For me it works on 10.3.2. Powershell 7.2 and PowerCli 12.5.

 

 

$CoresPerSocet = "2"
$CPU = "4"
$Vm = Get-CIVM -name "Vm_Name"

$VmView = $Vm | Get-CIView
$LinkAndType = $VmView.GetVirtualHardwareSection().any | ?{$_.href -match "/virtualHardwareSection/cpu" -and $_.rel -eq "edit"}
$APIVersion = "35.2"
$SessionId = $global:DefaultCIServers[0].SessionId
$Headers = @{'x-vcloud-authorization'=$SessionId;'Accept'="application/*+xml;version=$($APIVersion)"}
$CpuSection = Invoke-RestMethod -Method 'Get' -Uri $LinkAndType.href -Headers $Headers
$CpuSection.DocumentElement.CoresPerSocket."#text" = "$CoresPerSocet"
$CpuSection.DocumentElement.VirtualQuantity = "$CPU"
$Headers += @{'Content-Type'="$($LinkAndType.type)"}
$task = Invoke-RestMethod -Method 'Put' -Uri $LinkAndType.href -Headers $Headers -Body ($CpuSection.InnerXml)
Start-Sleep -Seconds 8
Search-Cloud -QueryType AdminTask -filter "Id==$($task.task.id)" | Select-Object OrgName, ObjectName, Status

 

 

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Hi LucD

thanks for your very fast answer! 😀

unfortunately, I cannot find an option for "Number of sockets"

 

RoyalFlash_0-1676290643253.png

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you expand the Any property?


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

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Hi LucD

I do not know a command to expand "Any" property.

How do I do this?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$cpu = $vm.ExtensionData.Section[0].Item | where{$_.Description.Value -eq 'Number of virtual CPUs'}
$cpu.Any


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

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

not sure if this is correct?

RoyalFlash_2-1676297371499.png

$vm = Get-Civm -name de-eelvdai-w01

$cpu = $vm.ExtensionData.Section[0].Item | where{$_.Description.Value -eq 'Number of virtual CPUs'}
$cpu.Any

required #text
-------- -----
false    1    
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try with

$cpu.Any.Value


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

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

 

 

Any.Value

 

does not exist

RoyalFlash_2-1676303927912.png

 

 

I checked it again and I believe this could work.

Please correct me if I am wrong.

Looking inside of $CPU.Any the output gives me #text = 8

RoyalFlash_5-1676304490668.png

 

$CPU = $CIVM.ExtensionData.Section[0].Item | Where-Object {$_.Description.Value -eq "Number of virtual CPUs" }
$CPU.Any

required #text
-------- -----
false    8   

 

 

But when I try to change #text I get following error:

RoyalFlash_4-1676304341944.png

 

PS C:\Users\eevanba> $CIVM = Get-Civm -name de-eelvdai-w01

$CPU = $CIVM.ExtensionData.Section[0].Item | Where-Object {$_.Description.Value -eq "Number of virtual CPUs" }
$CPU.Any[0].'#text' = 1
Cannot set "#text" because only strings can be used as values to set XmlNode properties.
At line:6 char:1
+ $CPU.Any[0].'#text' = 1
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueException
    + FullyQualifiedErrorId : XmlNodeSetShouldBeAString

 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, can't test since I don't have such an environment available.


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

0 Kudos
itsmeyounus
Contributor
Contributor
Jump to solution

Hi,

 

Have you tried keeping that in quotes like this.

$CPU.Any[0].'#text' = "1"

 

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

I always get a XML error with PowerShell 5.1

set XmlNode property.jpg

 

I do not understand exactly why, but it looks like this is working, only with PowerShell 7

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

VMware PowerCLI 13.0.0 Release Notes
Released 22 November 2022
VMware PowerCLI 13.0.0. Build 20829139

For Windows PowerShell 5.1, when you run a cmdlet and the operation fails on the server side, you might receive a There is an error in the XML document. error message.
This is not a valid server error and it is returned when PowerShell is unable to read the actual server-side error.
Workaround: Update to PowerShell 7 or use the vSphere Web Client to check the actual server-side error.

0 Kudos
Macleud
Enthusiast
Enthusiast
Jump to solution

Hi.

I'm not sure if it can be done (CoresPerSocet) via PowerCli.
Try using Powershell API.
For me it works on 10.3.2. Powershell 7.2 and PowerCli 12.5.

 

 

$CoresPerSocet = "2"
$CPU = "4"
$Vm = Get-CIVM -name "Vm_Name"

$VmView = $Vm | Get-CIView
$LinkAndType = $VmView.GetVirtualHardwareSection().any | ?{$_.href -match "/virtualHardwareSection/cpu" -and $_.rel -eq "edit"}
$APIVersion = "35.2"
$SessionId = $global:DefaultCIServers[0].SessionId
$Headers = @{'x-vcloud-authorization'=$SessionId;'Accept'="application/*+xml;version=$($APIVersion)"}
$CpuSection = Invoke-RestMethod -Method 'Get' -Uri $LinkAndType.href -Headers $Headers
$CpuSection.DocumentElement.CoresPerSocket."#text" = "$CoresPerSocet"
$CpuSection.DocumentElement.VirtualQuantity = "$CPU"
$Headers += @{'Content-Type'="$($LinkAndType.type)"}
$task = Invoke-RestMethod -Method 'Put' -Uri $LinkAndType.href -Headers $Headers -Body ($CpuSection.InnerXml)
Start-Sleep -Seconds 8
Search-Cloud -QueryType AdminTask -filter "Id==$($task.task.id)" | Select-Object OrgName, ObjectName, Status

 

 

0 Kudos