- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.
11-18-2025 04:17 AM
we want a powershell script that fetch reports from identity for audit purpose
any documents, script with readme
12-02-2025 08:01 AM
Likewise, use it at your own discretion and risk.
Below is an example script to hit the RedRock endpoint and run a custom SQL query. The setup assumes you have created an OAuth Client app with the appropriate scope, and an OAuth confidential client (service account with the appropriate roles\permissions to access the data you are looking for and entitlement to the OAuth client app).
Custom OAuth2 Client | CyberArk Docs
Add service users | CyberArk Docs
After the above is stood up should just need to populate the TenantUrl, AppId, ClientId values to be able to generate the bearer token then you can customize the sql string to contain the report info you are interested in gathering (in this example it grabs info on the roles defined in the tenant). You may need to tweak the scope parameter if you use an alternate value in your client app.
$TenantUrl = "" # or https://acme.my.idaptive.app
$AppId = "" # from the OAuth2 Client app
$ClientId = "" # e.g., apiuser@yourtenant
$ClientSecret= Read-Host -AsSecureString "Service user password" | `
ForEach-Object { [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_)) }
$TokenUrl = "$TenantUrl/oauth2/token/$AppId"
$body = @{
grant_type = 'client_credentials'
client_id = $ClientId
client_secret = $ClientSecret
scope = 'reporting' # scope created with REST Regex 'Redrock/query'
}
$tokenResponse = Invoke-RestMethod -Method POST -Uri $TokenUrl `
-ContentType 'application/x-www-form-urlencoded' -Body $body
$headers = @{ Authorization = "Bearer $($tokenResponse.access_token)" }
$headers | Format-List
#--------------------------------------------------------------------------------------
function Invoke-CyberArkIdentityQuery {
param(
[Parameter(Mandatory)]
[string]$TenantUrl,
[Parameter(Mandatory)]
[hashtable]$Headers,
[Parameter(Mandatory)]
[string]$Sql,
[int]$PageNumber = 1,
[int]$PageSize = 1000,
[int]$Limit = 1000,
[int]$Caching = -1, # live data, write to cache
[bool]$Ascending = $true
)
$uri = "$TenantUrl/Redrock/query"
$body = @{
Script = $Sql
args = @{
PageNumber = $PageNumber
PageSize = $PageSize
Limit = $Limit
Caching = $Caching
direction = $Ascending
SortBy = $SortBy
}
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method POST -Uri $uri -Headers $Headers `
-ContentType 'application/json' -Body $body
}
# Example: list user IDs and usernames, sorted case-insensitive
#$sql = "Select ID, Username from User ORDER BY Username COLLATE NOCASE"
#$sql = "Select * from Role WHERE RoleType = 'PrincipalList' ORDER BY Name COLLATE NOCASE"
$sql = "Select * from Role ORDER BY Name COLLATE NOCASE"
$result = Invoke-CyberArkIdentityQuery -TenantUrl $TenantUrl -Headers $headers -Sql $sql
$result.Result.Columns | ft
$result.Result.Results | ForEach-Object { $_.Row } | Select-Object ID, Name, ReadOnly, IsHidden, RoleType | Out-GridView
11-18-2025 05:39 AM
Not an expert, but you can hit the RedRock\Query endpoint to generate reports. I've only done this for some specific custom use cases, not to export output from the stock reports. Will share the OAuth client account you create to hit the endpoint will probably wind up needing the Read Only System Administration right as there is the right to access the reports but then you also need access to the underlying data that the report queries. This will materialize in the request returning success but no results when you know there should be results.
11-18-2025 07:00 PM
Hello @mohd azeem khan
There is a KB article explaining steps to generate Reports using REST API and PowerShell scripts.
Privilege Cloud Shared Services - Automate with REST API & PowerShell
I hope this will help you!
11-18-2025 07:00 PM
Hello @mohd azeem khan
There is a KB article explaining steps to generate Reports using REST API and PowerShell scripts.
Privilege Cloud Shared Services - Automate with REST API & PowerShell
I hope this will help you!
11-19-2025 12:54 AM
@Rohini Arora
in this above article report fetching is not present
help me on this
11-23-2025 07:00 PM
Hello @mohd azeem khan
For Reports
I hope this helps you!
11-23-2025 07:00 PM
Hello @mohd azeem khan
For Reports
I hope this helps you!
11-25-2025 04:39 AM
Hi @mohd azeem khan
Several community members have shared answers to your question, could you let us know if any of these resolved your issue?
If so, please mark the appropriate answer as “Select as Best” to help other members find the solution easily.
If the issue is still unresolved, I recommend raising a ticket with our support team for further assistance.
Thank you,
Shaked
12-02-2025 07:18 AM
CyberArk does not provide any officially documented or supported PowerShell scripts for generating reports. While I’m not a PowerShell expert, there is a script you might be able to adapt using RedRock queries:
https://github.com/jeffrechten/epv-api-scripts/blob/master/Identity%20Role%20Management/Role-Management.ps1
Please note: This script is not supported by CyberArk. Use it at your own discretion and risk.
12-02-2025 08:01 AM
Likewise, use it at your own discretion and risk.
Below is an example script to hit the RedRock endpoint and run a custom SQL query. The setup assumes you have created an OAuth Client app with the appropriate scope, and an OAuth confidential client (service account with the appropriate roles\permissions to access the data you are looking for and entitlement to the OAuth client app).
Custom OAuth2 Client | CyberArk Docs
Add service users | CyberArk Docs
After the above is stood up should just need to populate the TenantUrl, AppId, ClientId values to be able to generate the bearer token then you can customize the sql string to contain the report info you are interested in gathering (in this example it grabs info on the roles defined in the tenant). You may need to tweak the scope parameter if you use an alternate value in your client app.
$TenantUrl = "" # or https://acme.my.idaptive.app
$AppId = "" # from the OAuth2 Client app
$ClientId = "" # e.g., apiuser@yourtenant
$ClientSecret= Read-Host -AsSecureString "Service user password" | `
ForEach-Object { [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_)) }
$TokenUrl = "$TenantUrl/oauth2/token/$AppId"
$body = @{
grant_type = 'client_credentials'
client_id = $ClientId
client_secret = $ClientSecret
scope = 'reporting' # scope created with REST Regex 'Redrock/query'
}
$tokenResponse = Invoke-RestMethod -Method POST -Uri $TokenUrl `
-ContentType 'application/x-www-form-urlencoded' -Body $body
$headers = @{ Authorization = "Bearer $($tokenResponse.access_token)" }
$headers | Format-List
#--------------------------------------------------------------------------------------
function Invoke-CyberArkIdentityQuery {
param(
[Parameter(Mandatory)]
[string]$TenantUrl,
[Parameter(Mandatory)]
[hashtable]$Headers,
[Parameter(Mandatory)]
[string]$Sql,
[int]$PageNumber = 1,
[int]$PageSize = 1000,
[int]$Limit = 1000,
[int]$Caching = -1, # live data, write to cache
[bool]$Ascending = $true
)
$uri = "$TenantUrl/Redrock/query"
$body = @{
Script = $Sql
args = @{
PageNumber = $PageNumber
PageSize = $PageSize
Limit = $Limit
Caching = $Caching
direction = $Ascending
SortBy = $SortBy
}
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method POST -Uri $uri -Headers $Headers `
-ContentType 'application/json' -Body $body
}
# Example: list user IDs and usernames, sorted case-insensitive
#$sql = "Select ID, Username from User ORDER BY Username COLLATE NOCASE"
#$sql = "Select * from Role WHERE RoleType = 'PrincipalList' ORDER BY Name COLLATE NOCASE"
$sql = "Select * from Role ORDER BY Name COLLATE NOCASE"
$result = Invoke-CyberArkIdentityQuery -TenantUrl $TenantUrl -Headers $headers -Sql $sql
$result.Result.Columns | ft
$result.Result.Results | ForEach-Object { $_.Row } | Select-Object ID, Name, ReadOnly, IsHidden, RoleType | Out-GridView
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

