Classes/Public/PrismVM.ps1

# AHV VM configuration. Nested API objects are preserved without flattening them.
class PrismVM {
    [Nullable[bool]]$IsVcpuHardPinningEnabled
    [Nullable[bool]]$IsCpuPassthroughEnabled
    [Nullable[bool]]$IsMemoryOvercommitEnabled
    [Nullable[bool]]$IsGpuConsoleEnabled
    [Nullable[bool]]$IsCpuHotplugEnabled
    [Nullable[bool]]$IsScsiControllerEnabled
    [Nullable[bool]]$IsBrandingEnabled
    [Nullable[bool]]$IsVgaConsoleEnabled
    [Nullable[bool]]$IsAgentVm
    [Nullable[bool]]$IsLiveMigrateCapable
    [Nullable[bool]]$IsCrossClusterMigrationInProgress
    [Nullable[datetime]]$CreateTime
    [Nullable[datetime]]$UpdateTime
    [Nullable[int]]$NumSockets
    [Nullable[int]]$NumCoresPerSocket
    [Nullable[int]]$NumThreadsPerCore
    [Nullable[int]]$NumNumaNodes
    [Nullable[long]]$MemorySizeBytes
    [object]$Source
    [object]$Project
    [object]$OwnershipInfo
    [object]$Host
    [object]$Cluster
    [object]$AvailabilityZone
    [object]$GuestCustomization
    [object]$GuestTools
    [object]$BootConfig
    [object]$VtpmConfig
    [object]$ApcConfig
    [object]$StorageConfig
    [object]$RawData
    [object[]]$EnabledCpuFeatures
    [PrismCategory[]]$Categories
    [object[]]$Disks
    [object[]]$CdRoms
    [object[]]$Nics
    [object[]]$Gpus
    [object[]]$SerialPorts
    [object[]]$PcieDevices
    [object[]]$Links
    [string]$ExtId
    [string]$PrismSession
    [string]$Name
    [string]$Description
    [string]$GenerationUuid
    [string]$BiosUuid
    [string]$HardwareClockTimezone
    [string]$MachineType
    [string]$PowerState
    [string]$ProtectionType
    [string]$ProtectionPolicyState
    [string]$VmGuestCustomizationStatus
    [string]$TenantId
    [string[]]$CustomAttributes
    PrismVM() { }

    PrismVM([string]$extId) {
        if ([string]::IsNullOrWhiteSpace($extId)) { throw 'A VM ExtId is required.' }
        $this.ExtId = $extId
    }

    PrismVM([object]$data, [string]$prismSession) {
        if ($null -eq $data) { throw 'The API response did not contain VM data.' }
        $this.PrismSession = $prismSession
        $this.RawData = $data
        # A -Select projection may omit ExtId; commands acting on a VM validate it.
        foreach ($property in $this.psobject.Properties) {
            if ($property.Name -in @('PrismSession', 'RawData')) { continue }
            if ($property.Name -eq 'Categories') {
                $this.Categories = @(foreach ($category in $data.categories) {
                    [PrismCategory]::new($category, $prismSession)
                })
                continue
            }
            if ($data -is [System.Collections.IDictionary]) {
                if ($data.Contains($property.Name)) { $this.($property.Name) = $data[$property.Name] }
            } elseif ($data.psobject.Properties[$property.Name]) {
                $this.($property.Name) = $data.($property.Name)
            }
        }
    }

    [void]setSecureBoot([bool]$isSecureBootEnabled) {
        $this.RawData.bootConfig.isSecureBootEnabled = $isSecureBootEnabled
    }
}