Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shinusuresh/a2c3e252478fdd588085c1da5b8081af to your computer and use it in GitHub Desktop.

Select an option

Save shinusuresh/a2c3e252478fdd588085c1da5b8081af to your computer and use it in GitHub Desktop.
Cyberark powershell
$cyberArkHost = "<PVWA ADDRESS>"
$logonUrl = "https://$cyberArkHost/PasswordVault/API/auth/Cyberark/Logon"
$accountsUrl = "https://$cyberArkHost/PasswordVault/api/Accounts"
$username = Read-Host 'Username'
$pass = Read-Host 'Password' -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$logonBody = @{
Username = $username
Password = $password
}
$token = Invoke-RestMethod -Uri $logonUrl -Method Post -ContentType 'application/x-www-form-urlencoded' -Body $logonBody
$headers = @{
Authorization = $token
Accept = 'application/json'
}
$response = Invoke-RestMethod -Uri $accountsUrl -Method Get -Headers $headers
$accounts = $response.value | Select-Object `
id,
name,
userName,
address,
platformId,
safeName,
secretType,
createdTime
$accounts | Export-Csv -Path ".CyberArkAccounts.csv" -NoTypeInformation
$accounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment