Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Okta Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Okta data from PowerShell? This article demonstrates how to utilize the Okta Cmdlets for tasks like connecting to Okta data, automating operations, downloading data, and more.
The CData Cmdlets for Okta are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Okta.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Okta, but also an SQL interface; this tutorial shows how to use both to retrieve Okta data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Okta. To access Okta data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Okta.
Once you have acquired the necessary connection properties, accessing Okta data in PowerShell can be enabled in three steps.
To connect to Okta, set the Domain connection string property to your Okta domain.
You will use OAuth to authenticate with Okta, so you need to create a custom OAuth application.
Creating a Custom OAuth Application
From your Okta account:
- Sign in to your Okta developer edition organization with your administrator account.
- In the Admin Console, go to Applications > Applications.
- Click Create App Integration.
- For the Sign-in method, select OIDC - OpenID Connect.
- For Application type, choose Web Application.
- Enter a name for your custom application.
- Set the Grant Type to Authorization Code. If you want the token to be automatically refreshed, also check Refresh Token.
- Set the callback URL:
- For desktop applications and headless machines, use http://localhost:33333 or another port number of your choice. The URI you set here becomes the CallbackURL property.
- For web applications, set the callback URL to a trusted redirect URL. This URL is the web location the user returns to with the token that verifies that your application has been granted access.
- In the Assignments section, either select Limit access to selected groups and add a group, or skip group assignment for now.
- Save the OAuth application.
- The application's Client Id and Client Secret are displayed on the application's General tab. Record these for future use. You will use the Client Id to set the OAuthClientId and the Client Secret to set the OAuthClientSecret.
- Check the Assignments tab to confirm that all users who must access the application are assigned to the application.
- On the Okta API Scopes tab, select the scopes you wish to grant to the OAuth application. These scopes determine the data that the app has permission to read, so a scope for a particular view must be granted for the driver to have permission to query that view. To confirm the scopes required for each view, see the view-specific pages in Data Model < Views in the Help documentation.
PowerShell
-
Install the module:
Install-Module OktaCmdlets
-
Connect:
$okta = Connect-Okta -Domain "$Domain"
-
Search for and retrieve data:
$status = "Active" $users = Select-Okta -Connection $okta -Table "Users" -Where "Status = `'$Status`'" $users
You can also use the Invoke-Okta cmdlet to execute SQL commands:
$users = Invoke-Okta -Connection $okta -Query 'SELECT * FROM Users WHERE Status = @Status' -Params @{'@Status'='Active'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Okta\lib\System.Data.CData.Okta.dll")
-
Connect to Okta:
$conn= New-Object System.Data.CData.Okta.OktaConnection("Domain=dev-44876464.okta.com;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the OktaDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, ProfileFirstName from Users" $da= New-Object System.Data.CData.Okta.OktaDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.profilefirstname }