Public/Objects/Search-ABObjects.ps1
<#
.SYNOPSIS Search for a ActiveBatch object .DESCRIPTION Serves the .PARAMETER SearchPath Parameter description .PARAMETER Fields Array of fieldnames(strings) .PARAMETER Query A search string .PARAMETER ObjectTypes Parameter description .PARAMETER Limit Parameter description .PARAMETER Recursive Parameter description .PARAMETER All Return all records .EXAMPLE Search-ABObjects -All .NOTES General notes #> function Search-ABObjects { [CmdletBinding()] param( $SearchPath, [string[]]$Fields, [string]$Query, [ArgumentCompleter({ [OutputType([System.Management.Automation.CompletionResult])] param( [string] $CommandName, [string] $ParameterName, [string] $WordToComplete, [System.Management.Automation.Language.CommandAst] $CommandAst, [System.Collections.IDictionary] $FakeBoundParameters ) $CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new() foreach ($name in [ActiveBatchObjectTypes].GetEnumNames()) { $CompletionResults.Add([System.Management.Automation.CompletionResult]::new($name)) } return $CompletionResults })] [string[]]$ObjectTypes, [int]$Limit, [switch]$Recursive, [switch]$All ) begin { if ($All) { $Limit = 0xFFFFFF } } process { $Path = Get-ABPath -Path "SearchObjects" [System.UriBuilder]$Uri = "$($_ABSession.Uri)$Path" $HttpQSCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) if ($SearchPath) { $HttpQSCollection.Add('searchPath', $SearchPath) } if ($Limit) { $HttpQSCollection.Add('limit', $Limit) } if ($Query) { $HttpQSCollection.Add('query', $Query) } if ($Fields) { $HttpQSCollection.Add('fields', ($Fields -join ",")) } if ($ObjectTypes) { $HttpQSCollection.Add('objectTypes', ($ObjectTypes -join ",")) } if ($Recursive) { $HttpQSCollection.Add('recursive', 'true') } $uri.Query = $HttpQSCollection.ToString() $response = Invoke-ABRestMethod -Uri $Uri.Uri.OriginalString -method "GET" $response | ForEach-Object { $_.PSObject.TypeNames.Insert(0, "AB.Object") } $response } end { } } |