Functions/Accounts/Get-PASDependentAccount.ps1
|
# .ExternalHelp psPAS-help.xml function Get-PASDependentAccount { [CmdletBinding(DefaultParameterSetName = 'AllDependentAccounts')] param( [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificAccount' )] [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificDependentAccount' )] [Alias('AccountID')] [string]$id, [parameter( Mandatory = $true, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificDependentAccount' )] [string]$dependentAccountId, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificAccount' )] [ValidateLength(1, 500)] [string]$search, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [string]$MasterAccountId, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificAccount' )] [datetime]$modificationTime, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificAccount' )] [string]$platformId, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [string]$SafeName, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [bool]$includeDeleted, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificAccount' )] [bool]$failed, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'SpecificDependentAccount' )] [bool]$extendedDetails, [parameter( Mandatory = $false, ValueFromPipelinebyPropertyName = $true, ParameterSetName = 'AllDependentAccounts' )] [ValidateRange(1, 1000)] [int]$limit, [parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $false )] [int]$TimeoutSec ) begin { #check required version Assert-VersionRequirement -RequiredVersion 14.6 #Parameter to include as filter value in url $Parameters = [Collections.Generic.List[String]]@('MasterAccountId', 'modificationTime', 'platformId', 'SafeName') # Parameters that should not be included in filter string $IDParameters = [Collections.Generic.List[String]]@('id', 'dependentAccountId') #The url pattern is different between self-hosted and ISPSS #check for hosting type here if (Test-IsISPSS) { $URLString = 'account-dependents' if ($PSCmdlet.ParameterSetName -eq 'AllDependentAccounts') { #ISPSS cannot query for all dependent accounts Assert-VersionRequirement -SelfHosted } } else { $URLString = 'dependentAccounts' } }#begin process { #Get Parameters to include in request $boundParameters = $PSBoundParameters | Get-PASParameter -ParametersToRemove @($Parameters + $IDParameters) $filterParameters = $PSBoundParameters | Get-PASParameter -ParametersToKeep $Parameters $FilterString = $filterParameters | ConvertTo-FilterString # Determine base URI switch ($PSCmdlet.ParameterSetName) { 'SpecificAccount' { $URI = "$($psPASSession.BaseURI)/API/Accounts/$id/$URLString" } 'AllDependentAccounts' { $URI = "$($psPASSession.BaseURI)/API/dependentAccounts" if ($PSBoundParameters.Keys -notcontains 'Limit') { $Limit = 100 #default limit $boundParameters.Add('Limit', $Limit) # Add to boundparameters for inclusion in query string } } 'SpecificDependentAccount' { $URI = "$($psPASSession.BaseURI)/API/Accounts/$id/$URLString/$($dependentAccountId)" } } # Append filter string if present if ($null -ne $FilterString) { $boundParameters = $boundParameters + $FilterString } # Build query string $queryString = $boundParameters | ConvertTo-QueryString if ($queryString) { $URI = "$URI`?$queryString" } # Initial request $Result = Invoke-PASRestMethod -Uri $URI -Method GET -TimeoutSec $TimeoutSec if ($PSCmdlet.ParameterSetName -eq 'AllDependentAccounts') { # Page via Get-NextLink's offset support (API only provides a Total value) $Result = $Result | Get-NextLink -RequestUri $URI -TimeoutSec $TimeoutSec } if ($null -ne $Result) { $Result } } end { }#end } |