Public/Get-JuribaImportApplication.ps1
|
function Get-JuribaImportApplication { [alias("Get-DwImportApplication")] <# .SYNOPSIS Gets applications from the import API. .DESCRIPTION Gets applications from the import API. Takes the ImportId and UniqueIdentifier as an input. Optionally takes a UniqueIdentifier as an input and will return a single application with that UniqueIdentifier. Optionally takes a Filter as an input and will return all applications matching that filter. See swagger documentation for examples of using filters. If specified, only one of UniqueIdentifier or Filter can be supplied. Omit all to return all devices for the import. .PARAMETER Instance Optional. Instance to be provided if not authenticating using Connect-Juriba. For example, https://myinstance.platform.juriba.app:8443 .PARAMETER APIKey Optional. API key to be provided if not authenticating using Connect-Juriba. .PARAMETER ThrottleLimit Optional. Maximum number of pages to request concurrently on PowerShell 7+. Defaults to 8. Set to 1 to force sequential paging. .PARAMETER UniqueIdentifier UniqueIdentifier for the application. .PARAMETER ImportId ImportId for the application. .PARAMETER Filter Filter for application search. .PARAMETER Fields Array of fields to return. If specified, only these fields will be returned. This parameter is mutually exclusive with UniqueIdentifier and Filter. .PARAMETER InfoLevel Optional. Sets the level of information that this function returns. Accepts Basic or Full. Basic returns only the UniqueIdentifier, use when confirming an application exists. Full returns the full json object for the application. Default is Basic. .EXAMPLE PS> Get-JuribaImportApplication -Instance "https://myinstance.platform.juriba.app:8443" -APIKey "xxxxx" -ImportId 1 -InfoLevel "Full" .EXAMPLE PS> Get-JuribaImportApplication -Instance "https://myinstance.platform.juriba.app:8443" -APIKey "xxxxx" -ImportId 1 -UniqueIdentifier "123456789" -InfoLevel "Basic" .EXAMPLE PS> Get-JuribaImportApplication -Instance "https://myinstance.platform.juriba.app:8443" -APIKey "xxxxx" -ImportId 1 -Filter "eq(Manufacturer, 'zxy123456')" #> [OutputType([string])] [CmdletBinding(DefaultParameterSetName="Default")] param ( [Parameter(Mandatory=$true)] [string]$Instance, [Parameter(Mandatory=$true)] [string]$APIKey, [Parameter(Mandatory=$false, ParameterSetName="UniqueIdentifier")] [string]$UniqueIdentifier, [Parameter(Mandatory=$false, ParameterSetName="Filter")] [string]$Filter, [Parameter(Mandatory=$true)] [int]$ImportId, [Parameter(Mandatory=$false)] [ValidateSet("Basic", "Full")] [string]$InfoLevel = "Basic", [Parameter(Mandatory=$false ,ParameterSetName="fields")] [string[]]$Fields, [Parameter(Mandatory=$false)] [int]$PageSize = 200, [Parameter(Mandatory=$false)] [ValidateRange(1, 64)] [int]$ThrottleLimit = 8 ) if ((Get-Variable 'dwConnection' -Scope 'Global' -ErrorAction 'Ignore') -and !$APIKey -and !$Instance) { $APIKey = ConvertFrom-SecureString -SecureString $dwConnection.secureAPIKey -AsPlainText $Instance = $dwConnection.instance } if ($APIKey -and $Instance) { #Check if version is 5.14 or newer $ver = Get-JuribaDPCVersion -Instance $Instance -MinimumVersion "5.14" if ($ver) { $uri = "{0}/apiv2/imports/{1}/applications" -f $Instance, $ImportId } else { $uri = "{0}/apiv2/imports/applications/{1}/items" -f $Instance, $ImportId } #build query string $query = @() # add limit to query if not getting by UniqueIdentifier if ($PSCmdlet.ParameterSetName -ne "UniqueIdentifier") { $query += "limit=$PageSize" } # add parameters to query based on parameter set switch ($PSCmdlet.ParameterSetName) { "UniqueIdentifier" { $uri += "/{0}" -f $UniqueIdentifier } "Filter" { $query += "filter={0}" -f [System.Web.HttpUtility]::UrlEncode($Filter) } "Fields" { $query += "fields={0}" -f [System.Web.HttpUtility]::UrlEncode($Fields -join ',') $InfoLevel = "Full" } Default { } } # Fix for JRB-3457 / DAS-44911 for pre-Umbreon releases $query += "order=uniqueIdentifier" # build final uri if ($query.Count -gt 0) { $uri += $query | Join-String -Property $_ -Separator "&" -OutputPrefix "?" } $headers = @{'x-api-key' = $APIKey} $application = "" try { $items = Invoke-JuribaPagedRequest -Uri $uri -Headers $headers -ThrottleLimit $ThrottleLimit $application = switch($InfoLevel) { "Basic" { $items.UniqueIdentifier } "Full" { $items } } } catch { if ($_.Exception.Response.StatusCode.Value__ -eq 404) { # 404 means the application was not found, don't treat this as an error # as we expect this function to be used to check if a application exists Write-Verbose "application not found" } else { Write-Error $_ } } return $application } else { Write-Error "No connection found. Please ensure `$APIKey and `$Instance is provided or connect using Connect-Juriba before proceeding." } } |