Powershell script to list for users that were deprovisioned over 60 days from current date Skip to main content
https://support.okta.com/help/answers?id=9062a000000xal6qak&refurl=http%3a%2f%2fsupport.okta.com%2fhelp%2fanswers
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
1
2
3
4
5
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.
Ask Search:
Caven BarrettCaven Barrett 

Powershell script to list for users that were deprovisioned over 60 days from current date

I currently have the below script that shows me all the users in a deprovisioned status but I would like to filter that further only those with a statusChanged date older than 60 days.
I am not a developer and am very new to scripting in powershell so any help you can provide is appreciated.

Sample Script below
------------------------------------------------------------------------------------------
$users = oktaListDeprovisionedUsers -oOrg PROD1
$toexport = New-Object System.Collections.ArrayList

New-Item -Path "c:\" -Name "OktaExport" -Itemtype directory -Force

Foreach ($u in $users)
{
    $line = @{
              status = $u.status
              employeeid = $u.profile.employeeNumber
              firstName = $u.profile.firstName
              lastName = $u.profile.lastName
              email = $u.profile.email
              department = $u.profile.department
              supervisor = $u.profile.manager
              created = $u.created
              lastUpdated = $u.lastUpdated
              login = $u.profile.login
              title = $u.profile.title
              GroupName = $u.profile.Group_Name
              Organization = $u.profile.organization
              Location = $u.profile.workday_location
              User_type = $u.profile.userType
              StatusChanged = $u.StatusChanged
                                   

             }
    $obj = New-Object psobject -Property $line
    $_c = $toexport.Add($obj)
}
#Path for utility will have to be changed to a more generic location.
$toexport | Export-Csv -Path "C:\OktaExport\user-list.csv" -NoTypeInformation

---------------------------------------------------------------------------------------------------------------------------
Best Answer chosen by Dylann Fezeu (Customer First Programs)
FlorinFlorin (Okta, Inc.) 
Here (https://developer.okta.com/docs/api/resources/users?_ga=2.233082589.214620579.1522068894-578507945.1513367079#list-users-with-a-filter) is the documantation that we have on listing users with a filter. While not specific to PS it should get you started. 

All Answers

FlorinFlorin (Okta, Inc.) 
Here (https://developer.okta.com/docs/api/resources/users?_ga=2.233082589.214620579.1522068894-578507945.1513367079#list-users-with-a-filter) is the documantation that we have on listing users with a filter. While not specific to PS it should get you started. 
This was selected as the best answer
Dylann FezeuDylann Fezeu (Customer First Programs)
Hi,

Thanks for posting your inquiry in Okta Community Portal.

If you receive a great answer to your question(s), please help readers find it by marking it the best answer. Hover over the answer and click "Best Answer." 

Thank you,

Dylann Fezeu
Okta Help Center Team