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
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
Have a look at Re: set vCloud Director vApp VM memory and hardwar... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
thanks for your very fast answer! 😀
unfortunately, I cannot find an option for "Number of sockets"
Did you expand the Any property?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I do not know a command to expand "Any" property.
How do I do this?
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
not sure if this is correct?
$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
Hi LucD,
Any.Value
does not exist
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
$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:
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
Sorry, can't test since I don't have such an environment available.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Have you tried keeping that in quotes like this.
$CPU.Any[0].'#text' = "1"
I always get a XML error with PowerShell 5.1
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.
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