Fetch All Safe Permission details in Privilege Cloud

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

Fetch All Safe Permission details in Privilege Cloud

L4 Transporter

Developed and utilized a script to retrieve Safe Permissions for all safes within Privilege Cloud.

Note:I used POSTMAN to generate the required token for script execution; however, this step can also be automated(not achieved in the below script).

=============================================

$baseUrl = "https://CustomerTenant.privilegecloud.cyberark.cloud/PasswordVault"

$rawToken = Read-Host "Paste your CyberArk Bearer token (do NOT include the 'Bearer ' prefix)"

$outputCsv = "C:\temp\safemembers_full_detailed.csv"

$limit = 100

 

$headers = @{

  "Authorization" = "Bearer $rawToken"

  "Content-Type" = "application/json"

}

 

# Retrieve all safes

$allSafes = @()

$offset = 0

do {

  $safesResult = Invoke-RestMethod -Uri "$baseUrl/api/Safes?limit=$limit&offset=$offset" -Headers $headers -Method Get

  $pageSafes = $safesResult.value

  $allSafes += $pageSafes

  $offset += $limit

} while ($pageSafes.Count -eq $limit)

 

# Collect all possible permission names

$permissionPropertySet = @{}

 

# Pass 1: Gather ALL permission names present

foreach ($safe in $allSafes) {

  $safeName = $safe.SafeName

  $encodedSafeName = [uri]::EscapeDataString($safeName)

  $uri = "$baseUrl/api/Safes/$encodedSafeName/Members"

  try {

    $members = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get

    foreach ($member in $members.value) {

      foreach ($perm in $member.Permissions.PSObject.Properties.Name) {

        $permissionPropertySet[$perm] = $true

      }

    }

  } catch {}

}

 

$permissionProperties = $permissionPropertySet.Keys

 

# Pass 2: Export to CSV, flatten permissions

$allMembers = foreach ($safe in $allSafes) {

  $safeName = $safe.SafeName

  $encodedSafeName = [uri]::EscapeDataString($safeName)

  $uri = "$baseUrl/api/Safes/$encodedSafeName/Members"

  try {

    $members = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get

    foreach ($member in $members.value) {

      $obj = [ordered]@{

        SafeName  = $safeName

        MemberName = $member.MemberName

      }

      foreach ($perm in $permissionProperties) {

        $obj[$perm] = $member.Permissions.$perm

      }

      [PSCustomObject]$obj

    }

  } catch {}

}

 

if ($allMembers) {

  $allMembers | Export-Csv -NoTypeInformation -Path $outputCsv

  Write-Host "Exported all safe memberships with detailed permissions to $outputCsv" -ForegroundColor Green

} else {

  Write-Host "No memberships found to export." -ForegroundColor Yellow

}

=============================================

1 REPLY 1

L4 Transporter

Hi @Amit Maharana​ ,

As the community has not yet responded to this question, could you kindly share if you found a solution independently? If so, please share it to assist other community members.

If the issue is still unresolved, I recommend opening a support case to get direct assistance from our team.

 

Thank you, Omri

  • 141 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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!