- saveEventLogs.ps1 is a powershell script written to collect and store events from Okta
- saveEventLogsV2.ps1 is a powershell script written to collect and store logs from Okta
In theory These should run on any platform capable of running powershell (pwsh), i have tested it on OS-X and Windows 10
- The script relies on my powershell module for Okta, Okta-PSModule
- events/logs are saved in a text file using the JSON Lines format
- events/logs are saved in a datestamped file based on the published time of the event
- a datestamped file is only created if an event occured on that day
128 -rw-r--r-- 1 matt staff 64917 Nov 10 06:51 OktaLog_matt_2017-11-01.jsonl 32 -rw-r--r-- 1 matt staff 14243 Nov 10 06:51 OktaLog_matt_2017-11-02.jsonl 176 -rw-r--r-- 1 matt staff 87505 Nov 10 06:51 OktaLog_matt_2017-11-03.jsonl 16 -rw-r--r-- 1 matt staff 6708 Nov 10 06:51 OktaLog_matt_2017-11-04.jsonl 8 -rw-r--r-- 1 matt staff 2208 Nov 10 06:51 OktaLog_matt_2017-11-05.jsonl 8 -rw-r--r-- 1 matt staff 1247 Nov 10 06:51 OktaLog_matt_2017-11-06.jsonl 912 -rw-r--r-- 1 matt staff 453712 Nov 10 06:51 OktaLog_matt_2017-11-07.jsonl 88 -rw-r--r-- 1 matt staff 41084 Nov 10 06:51 OktaLog_matt_2017-11-08.jsonl 8 -rw-r--r-- 1 matt staff 1247 Nov 10 06:51 OktaLog_matt_2017-11-09.jsonl 24 -rw-r--r-- 1 matt staff 10998 Nov 10 07:06 OktaLog_matt_2017-11-10.jsonl
- Feedback is welcome
- Follow these instructions to download and configure the Okta-PSModule
- Make note of the org name you use
- Mine is called 'matt'
- Download and Save the saveEventLogs.ps1 or saveEventLogsV2.ps1to your computer
- Mine lives in
C:\Users\username\Documents\WindowsPowerShell\Modules\Okta-Scripts
- Mine lives in
- Create a directory where you'd like to store your logs
- Mine lives in
C:\logs\
- Mine lives in
- Open a command prompt or terminal window
- Change to the directory you want to store you logs in
cd C:\logs - Execute the script (replace script location, orgname and startDate with your values)
# save events on windows powershell -file C:\Users\username\Documents\WindowsPowerShell\Modules\Okta-Scripts\saveEvents.ps1 -oOrg matt -startDate 2017-01-01 # save system logs on mac powershell -file /Users/username/.local/share/powershell/Modules/Okta-Scripts/saveEventLogsV2.ps1 -oOrg matt -startDate 2017-01-01
- .state_orgname (V1) or .logState_orgname (V2) The first time you run the script a file will be created called
.state_<orgname>(V1) or.logState_<orgname>(V2). This file is used for ongoing collection and is used to keep track of the date and eventId of the last event retrieved.
When the script executes it will look in its current directory for a .state__orgname_ file, if found the startDate is retrieved from that file and the command line argument startDate value is ignored
You may find it convienient to create a link to the script file
- Linux/Mac
cd /logs ln -s /users/username/.local/share/powershell/Modules/Okta-Scripts/saveEvents.ps1 .
- Windows
cd C:\logs mklink saveEvents.ps1 C:\Users\username\Documents\WindowsPowerShell\Modules\Okta-Scripts\saveEvents.ps1
see: windows task scheduler
see: crontab