VMware Cloud Community

Change GuestOS Type of vApp VM programmatically using PowerCLI

I have a use case where I have a large amount of imported VMs into vCD - everything looks good except the GuestOSType is incorrect - I have a powercli script that will list the OS Type but I can't seem to find a way to set it to the desired new value

To display what it is, I can simply add  $OS = $vm.GuestOSFullName

If i try $vm.GuestOSFullName = "Value"

I get error saying it is a read only value - "'GuestOSFullName' is a ReadOnly property."

I think i need to use extensiondata but cant seem to find a similar example of setting spec - 


Has anyone achieved this before or know where i would get an example of setting guestos from powercli on Cloud Director VMs


I know from vCenter i can use powercli to change it - but am slow to do it from the vCenter side as it doesn't seem to change the vCD OS - On vCenter side it is just the commandlet Set-VM -VM $vm -GuestId $guestId -confirm:$false 




0 Kudos
1 Reply

API requests can be used for your task.
But on vCloud 10.4 and newer, this won't work.

$GuestOsType = "windows9Server64Guest"
$Vm = Get-CIVM -name "My_Vm_Name"

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