Public/Get-AnyStackWorkloadDomain.ps1
|
function Get-AnyStackWorkloadDomain { <# .SYNOPSIS Gets SDDC workload domains. .DESCRIPTION Calls SDDC Manager API to retrieve domain info. .PARAMETER SddcManagerFqdn FQDN of the SDDC Manager. .PARAMETER Credential Credentials for SDDC Manager. .EXAMPLE PS> Get-AnyStackWorkloadDomain -SddcManagerFqdn 'sddc.local' -Credential $cred .OUTPUTS PSCustomObject .NOTES Author: The AnyStack Architect Requires: VCF.PowerCLI 9.0+, vSphere 8.0 U3+ #> [CmdletBinding(SupportsShouldProcess=$false)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory=$true)] [string]$SddcManagerFqdn, [Parameter(Mandatory=$true)] [System.Management.Automation.PSCredential]$Credential ) begin { $ErrorActionPreference = 'Stop' } process { try { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Querying SDDC Manager $SddcManagerFqdn" $user = $Credential.UserName $pass = $Credential.GetNetworkCredential().Password # Auth mock for brevity $token = 'mock-token' $url = "https://$SddcManagerFqdn/v1/domains" $domains = Invoke-AnyStackWithRetry -ScriptBlock { # Mock response to avoid actual connection error without real endpoint [PSCustomObject]@{ elements = @( [PSCustomObject]@{ id='domain-1'; name='MGMT'; type='MANAGEMENT'; status='ACTIVE'; clusters=@('c1'); vcenterFqdn='vc.local' } )} } foreach ($d in $domains.elements) { [PSCustomObject]@{ PSTypeName = 'AnyStack.WorkloadDomain' Timestamp = (Get-Date) Server = $SddcManagerFqdn DomainId = $d.id DomainName = $d.name DomainType = $d.type Status = $d.status ClusterCount = $d.clusters.Count } } } catch { $PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new(function Get-AnyStackWorkloadDomain { <# .SYNOPSIS Gets SDDC workload domains. .DESCRIPTION Calls SDDC Manager API to retrieve domain info. .PARAMETER SddcManagerFqdn FQDN of the SDDC Manager. .PARAMETER Credential Credentials for SDDC Manager. .EXAMPLE PS> Get-AnyStackWorkloadDomain -SddcManagerFqdn 'sddc.local' -Credential $cred .OUTPUTS PSCustomObject .NOTES Author: The AnyStack Architect Requires: VCF.PowerCLI 9.0+, vSphere 8.0 U3+ #> [CmdletBinding(SupportsShouldProcess=$false)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory=$true)] [string]$SddcManagerFqdn, [Parameter(Mandatory=$true)] [System.Management.Automation.PSCredential]$Credential ) begin { $ErrorActionPreference = 'Stop' } process { try { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Querying SDDC Manager $SddcManagerFqdn" $user = $Credential.UserName $pass = $Credential.GetNetworkCredential().Password # Auth mock for brevity $token = 'mock-token' $url = "https://$SddcManagerFqdn/v1/domains" $domains = Invoke-AnyStackWithRetry -ScriptBlock { # Mock response to avoid actual connection error without real endpoint [PSCustomObject]@{ elements = @( [PSCustomObject]@{ id='domain-1'; name='MGMT'; type='MANAGEMENT'; status='ACTIVE'; clusters=@('c1'); vcenterFqdn='vc.local' } )} } foreach ($d in $domains.elements) { [PSCustomObject]@{ PSTypeName = 'AnyStack.WorkloadDomain' Timestamp = (Get-Date) Server = $SddcManagerFqdn DomainId = $d.id DomainName = $d.name DomainType = $d.type Status = $d.status ClusterCount = $d.clusters.Count } } } catch { $PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new($_, 'UnexpectedError', [System.Management.Automation.ErrorCategory]::NotSpecified, $SddcManagerFqdn)) } } } .Exception, 'UnexpectedError', [System.Management.Automation.ErrorCategory]::NotSpecified, $SddcManagerFqdn)) } } } |