Public/Get-SbTenant.ps1
|
function Get-DuneTenant { [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(ParameterSetName = "Tenant", ValueFromPipelineByPropertyName)] [guid]$TenantId, [Parameter()] [switch]$Raw ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $Uri = "tenants" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" try { $Response = Invoke-DuneApiRequest -Uri $Uri -Method $Method $Results = if ($Response.Content) { $Response.Content | ConvertFrom-Json } $ReturnObjects += $Results | ForEach-Object { if ($Raw) { $_ } else { ConvertTo-DuneClassObject -Class DuneTenant -InputObject $_ } } } catch { throw $_ } } end { Write-Debug "$($MyInvocation.MyCommand)|end" # Filters switch ($PSCmdlet.ParameterSetName) { 'Tenant' { $ReturnObjects = $ReturnObjects | Where-Object id -EQ $TenantId } Default {} } return $ReturnObjects | Sort-Object -Unique Id | Sort-Object Name } } |