<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z0000AKADRrCQPOkta Classic EngineAdministrationAnswered2025-03-07T21:59:35.000Z2025-03-07T16:37:54.000Z2025-03-07T21:59:35.000Z

JuanS.53128 (Customer) asked a question.

Generating User Report with Attributes using Powershell/API

I am using the script below to pull a list of all our users via API and generating a CSV off of it.

 

The issue I am having is that I cannot grab certain properties like lastlogin and status to add to the CSV because it is in the id property (last section of script). Is there an an easy way to accomplish this?

 

<*

Name: get-oktaGroupMembers.ps1

Purpose: Script for exporting Okta group membership to a csv file

Author: chris@neely.pro

Notes: Requires PowerShell 3.0 or later

Example: .\get-oktaGroupMembers.ps1 -org "tenant-okta.login.adsbillinghub.com" -api_token "0000" -path "c:\scripts\groupname.csv"

*>

 

*requires -version 3.0

 

param(

   [Parameter(Mandatory=$true)]$org, * Your tentant prefix - Ex. tenant-okta.login.adsbillinghub.com

   [Parameter(Mandatory=$true)]$api_token, * Your API Token. You can generate this from Admin - Security - API

   [Parameter(Mandatory=$true)]$path * The path and file name for the resulting CSV file

   )

 

*** Define $allusers as empty array

$allusers = @()

 

$headers = @{"Authorization" = "SSWS $api_token"; "Accept" = "application/json"; "Content-Type" = "application/json"}

 

*** Set $uri as the API URI for use in the loop

$uri = "https://$org/api/v1/users"

 

*** Use a while loop and get all users from Okta API

do {

   $webresponse = Invoke-WebRequest -Headers $headers -Method Get -Uri $uri

   $links = $webresponse.Headers.Link.Split("<").Split(">")

   $uri = $links[3]

   $users = $webresponse | ConvertFrom-Json

   $allusers += $users

} while ($webresponse.Headers.Link.EndsWith('rel="next"'))

 

*** Filter the results and remove any DEPROVISIONED users

$activeUsers = $allusers * | Where-Object { $_.status -ne "DEPROVISIONED" }

 

*** Select the user profile properties we want and export to CSV

$activeUsers | Select-Object -ExpandProperty profile |

   Select-Object -Property lastName, firstName, email, secondemail, manager, department |

   Export-Csv -Path $path -NoTypeInformation


This question is closed.
Loading
Generating User Report with Attributes using Powershell/API