<# =========================================================================== Created on: 12/17/2024 10:35 AM Created by: Alexis Lazcano Organization: Saratoga Corporate Management Group, LLC Filename: PSIsonas.psm1 ------------------------------------------------------------------------- Module Name: PSIsonas =========================================================================== #> Function Get-IsonasRequestHeaders { $tokenPair = "$env:ISONAS_TokenID`:$env:ISONAS_TokenValue" $tokenBase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($tokenPair)) $Headers = @{ 'Authorization' = "Basic $tokenBase64" 'Content-Type' = 'application/merge-patch+json' } return $Headers } function Test-IsonasConnection { $API_Users = $env:ISONAS_API_URL + "users" $Response = Invoke-RestMethod -Uri "$API_Users/?includeDisabled=false&limit=1" -Headers $(Get-IsonasRequestHeaders) if ($Reponse.Status -eq "Success") { return $true } else { return $false } } function Get-IsonasUsers { param ( [Parameter(Position = 1)] [switch]$All, [Parameter(Mandatory = $false, Position = 2)] [ValidateNotNullOrEmpty()] [int]$Limit = 200, [Parameter(Position = 3)] [bool]$IncludeDisabled = $false ) $API_Users = $env:ISONAS_API_URL + "users" if ($All) { Write-Host "All users was used" $TargetUrl = "$API_Users/" } else { Write-Host "All users was NOT used" $TargetUrl = "$API_Users/?includeDisabled=$IncludeDisabled&limit=$Limit" } $Response = Invoke-RestMethod -Uri $TargetUrl -Headers $(Get-IsonasRequestHeaders) -Method GET $flattened = $response | ForEach-Object { $obj = [PSCustomObject]@{ Id = $_.Id CreatedTime = $_.createdTime UpdatedTime = $_.updatedTime FirstName = $_.firstName LastName = $_.lastName AreaID = $_.areaId EmployeeId = $_.employeeId IsDisabled = $_.isDisabled } foreach ($field in $_.userDefinedFields) { $propertyName = $field.name -replace '\s', '' $obj | Add-Member -MemberType NoteProperty -Name $propertyName -Value $field.value } $obj } return $flattened }