Public/Get-DuneUser.ps1
|
function Get-DuneUser { <# .SYNOPSIS Queries Dune user #> [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(ParameterSetName = "Id")] [int]$Id, [Parameter(ParameterSetName = "StringFilters")] [string]$FirstName, [Parameter(ParameterSetName = "StringFilters")] [string]$LastName, [Parameter(ParameterSetName = "StringFilters")] [string]$Email, [Parameter()] [switch]$Raw, [Parameter()] [switch]$IncludeDeleted ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $ProcessedUrls = @() $BaseUri = "authentication/users" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" # Build Uri $Uri = switch ($PSCmdlet.ParameterSetName) { 'Id' { '{0}?Id={1}' -f $BaseUri, $Id } Default { $BaseUri } } if ($FirstName) { $Uri = $Uri | Add-UriQueryParam "FirstNameILike=$FirstName" -ConvertWildcards } if ($LastName) { $Uri = $Uri | Add-UriQueryParam "LastNameILike=$LastName" -ConvertWildcards } if ($Email) { $Uri = $Uri | Add-UriQueryParam "EmailILike=$Email" -ConvertWildcards } if ($IncludeDeleted) { $Uri = $Uri | Add-UriQueryParam "IncludeDeleted=1" } # ApiCall and Object conversion if ($ProcessedUrls -notcontains $Uri) { try { $Response = Invoke-DuneApiRequest -Uri $Uri -Method $Method -ErrorAction Continue $Results = if ($Response.Content) { $Response.Content | ConvertFrom-Json } $ReturnObjects += $Results.items | ForEach-Object { if ($Raw) { $_ } else { ConvertTo-DuneClassObject -Class DuneUser -InputObject $_ } } } catch { throw $_ } } else { Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked" } } end { Write-Debug "$($MyInvocation.MyCommand)|end" return $ReturnObjects } } |