public/Get-DuoUser.ps1
|
<# .Synopsis Retrieve DUO Users .DESCRIPTION Returns a list of users. If username is not provided, the list will contain all users. If username is provided, the list will either contain a single user (if a match was found) or no users. .EXAMPLE Get-DuoUser .EXAMPLE Get-DuoUser -username 'i842459' .INPUTS [string]UserName .OUTPUTS [PSCustomObject]DuoRequest .NOTES DUO API Method GET Path /admin/v1/users PARAMETERS Parameter Required? Description username Optional Specify a username to look up a single user. RESPONSE CODES Response Meaning 200 Success. Returns a list of users. 400 Invalid parameters. .COMPONENT The component this cmdlet belongs to .FUNCTIONALITY The functionality that best describes this cmdlet #> function Get-DuoUser() { [CmdletBinding()] param ( [parameter(Mandatory = $false)] [String]$username ) [string]$method = "GET" [string]$path = "/admin/v1/users" $APiParams = $MyInvocation.BoundParameters if($username){ $DuoRequest = Convertto-DUORequest -DuoMethodPath $path -Method $method -ApiParams $ApiParams $Response = Invoke-RestMethod @DuoRequest -SkipHeaderValidation:$true #$response = invoke-webrequest @DuoRequest # -SkipHeaderValidation If ($Response.stat -ne 'OK') { Write-Warning 'DUO REST Call Failed' Write-Warning "APiParams:"+($APiParams | Out-String) Write-Warning "Method:$method Path:$path" } $Output = $Response | Select-Object -ExpandProperty Response Write-Output $Output }else{ $outputs = [System.Collections.Generic.List[pscustomobject]]::new() $offsets = [system.collections.generic.list[string]]::new() $offsets.add('0') $offsets.add('100') $offsets.add('200') $offsets.add('300') $offsets.add('400') $offsets.add('500') $offsets.add('600') $offsets.add('700') $offsets.add('800') $offsets.add('900') $offsets.add('1000') $offsets.add('1100') $offsets.add('1200') $offsets.add('1300') $offsets.add('1400') $offsets.add('1500') $offsets.add('1600') $offsets.add('1700') $offsets.add('1800') $offsets.add('1900') $offsets.add('2000') foreach($offset in $offsets){ $apiparams = [system.collections.generic.dictionary[string, string]]::new() $apiparams.add('offset', $offset) $DuoRequest = Convertto-DUORequest -DuoMethodPath $path -Method $method -ApiParams $ApiParams $Response = Invoke-RestMethod @DuoRequest -SkipHeaderValidation:$true If ($Response.stat -ne 'OK') { Write-Warning 'DUO REST Call Failed' Write-Warning ($APiParams | Out-String) Write-Warning "Method:$method Path:$path" } $outputs.add($response.response) } # end of foreach $outputs = $outputs.getenumerator().foreach({$_}) write-output -InputObject $outputs } # end of else } |