Private/Get-AtwsDefinition.ps1
Function Get-AtwsDefinition { Begin { $EntityName = '#EntityName' # Enable modern -Debug behavior If ($PSCmdlet.MyInvocation.BoundParameters['Debug'].IsPresent) {$DebugPreference = 'Continue'} Write-Debug ('{0}: Begin of function' -F $MyInvocation.MyCommand.Name) } Process { If ($PSCmdlet.ParameterSetName -eq 'Get_all') { $Filter = @('id', '-ge', 0) } ElseIf (-not ($Filter)) { Write-Debug ('{0}: Query based on parameters, parsing' -F $MyInvocation.MyCommand.Name) # Convert named parameters to a filter definition that can be parsed to QueryXML $Filter = ConvertTo-AtwsFilter -BoundParameters $PSBoundParameters -EntityName $EntityName } Else { Write-Debug ('{0}: Query based on manual filter, parsing' -F $MyInvocation.MyCommand.Name) $Filter = . Update-AtwsFilter -FilterString $Filter } $Caption = $MyInvocation.MyCommand.Name $VerboseDescrition = '{0}: About to query the Autotask Web API for {1}(s).' -F $Caption, $EntityName $VerboseWarning = '{0}: About to query the Autotask Web API for {1}(s). Do you want to continue?' -F $Caption, $EntityName If ($PSCmdlet.ShouldProcess($VerboseDescrition, $VerboseWarning, $Caption)) { # Make the query and pass the optional parameters to Get-AtwsData $Result = Get-AtwsData -Entity $EntityName -Filter $Filter ` -NoPickListLabel:$NoPickListLabel.IsPresent ` -GetReferenceEntityById $GetReferenceEntityById ` -GetExternalEntityByThisEntityId $GetExternalEntityByThisEntityId Write-Verbose ('{0}: Number of entities returned by base query: {1}' -F $MyInvocation.MyCommand.Name, $Result.Count) } } End { Write-Debug ('{0}: End of function' -F $MyInvocation.MyCommand.Name) If ($Result) { Return $Result } } } |