
JuanS.53128 (Customer) asked a question.
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.com" -api_token "0000" -path "c:\scripts\groupname.csv"
*>
*requires -version 3.0
param(
[Parameter(Mandatory=$true)]$org, * Your tentant prefix - Ex. tenant.okta.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

Hello @JuanS.53128 (Customer) , thank you for contacting Okta Community!
I've reviewed our documentation for something relevant. It looks like your question is more appropriate for our dedicated Okta Developer Forum. I advise reaching out via devforum.okta.com as they will have more insight into this topic.
In the meantime, you can reference this article from Okta Developer:
How to Use Okta's PowerShell Module to Manage Your Okta Org
There is also this older thread that you may find interesting:
Utilizing Powershell for user reporting and modification
While we'll do our best to answer your questions here, this medium is more inclined towards Okta's core products and features (non-developer work).
Regards.
--
Help others in the community by liking or hitting Select as Best if this response helped you.
Thank you - I think I figured it out.