Public/User/Get-PopuliUsers.ps1
function Get-PopuliUsers { [CmdletBinding(PositionalBinding = $true)] param ( [Parameter(Mandatory = $false)][switch]$IncludePersonDetails, [Parameter(Mandatory = $false)][ValidateLength(200, 999)][string]$PopuliToken = $env:PopuliToken, [Parameter(Mandatory = $false)][ValidatePattern('^(?i)https:\/\/\S+\.populiweb\.com\/?$')][string]$BaseUrl = $env:PopuliBaseUrl ) if ($BaseUrl -match '\/$') { $BaseUrl = $BaseUrl -replace '\/$' } $header = @{ Authorization = $PopuliToken } $body = @{ task = 'getUsers' } try { $response = Invoke-RestMethod -Uri "$BaseUrl/api/" -Method POST -ContentType 'application/x-www-form-urlencoded' -Body $body -Headers $header $allUsers = $response.response.person if ($IncludePersonDetails) { $returnObj = @() $count = $allUsers.Count $i = $count $j = 0 foreach ($user in $allUsers) { try { Write-Progress -Activity "Getting Person Details for: $($user.userName)" -Status "$i Users Remaining.." -PercentComplete (($j / $count) * 100) -ErrorAction Ignore $i-- $j++ } catch { } $person = $null $person = Get-PopuliPerson -PersonId $user.person_id -LogResult: $false if ($person) { $person | Add-Member -MemberType NoteProperty -Name blocked -Value $user.blocked -Force $returnObj += $person } } Write-Log "Returning $($returnObj.Count) users including person details" return $returnObj } else { Write-Log "Returning $($allUsers.Count) users without person details" return $allUsers } } catch { Write-Log "Unhandled exception" -LogType: error -ErrorObject $_ Write-Error $_ return $null } } |