Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Created April 25, 2024 16:18
Show Gist options
  • Save infamousjoeg/834534f66a9d87a9503f1823bceecc50 to your computer and use it in GitHub Desktop.
Save infamousjoeg/834534f66a9d87a9503f1823bceecc50 to your computer and use it in GitHub Desktop.
PowerShell script that creates test users for CyberArk Identity Security Platform SaaS
# Import PowerShell module psPAS, if it doesn't exist, install it
Import-Module psPAS -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Install-Module psPAS -Force
Import-Module psPAS
}
# Import PowerShell module IdentityCommand, if it doesn't exist, install it
Import-Module IdentityCommand -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Install-Module IdentityCommand -Force
Import-Module IdentityCommand
}
# Ask for CyberArk credentials
$cred = Get-Credential -Title "CyberArk Credentials" -Message "Please enter your CyberArk credentials"
# Connect to CyberArk
$session = @{
IdentityTenantURL = "https://xxx1234.id.cyberark.cloud"
PrivilegeCloudURL = "https://subdomain.privilegecloud.cyberark.cloud"
Credential = $cred
ServiceUser = $true
}
New-PASSession @session -ErrorAction Stop
Write-Output "+ Connected to CyberArk Identity Security Platform"
# Create a new CyberArk Safe
$safe = @{
SafeName = "TestSafeName"
Description = "This is a safe containing users for testing."
ManagingCPM = "PasswordManager"
NumberOfDaysRetention = 0
}
Add-PASSafe @safe -ErrorAction SilentlyContinue
Write-Output "+ Safe created"
# Loop 311 times to create 311 accounts in the new safe with a random password and a random username
for ($i = 0; $i -lt 311; $i++) {
$username = "TestUser" + $i
$password = $(ConvertTo-SecureString -String $(-join ((65..90) + (97..122) | Get-Random -Count 16 | ForEach-Object {[char]$_})) -AsPlainText -Force)
Add-PASAccount -SafeName "TestSafeName" -Address "Address" -UserName $username -Password $password -PlatformID "MSSQL" -disableAutoMgmt $true -ErrorAction SilentlyContinue
Write-Output "+ Account $username created"
Start-Sleep -Seconds 1
}
Close-PASSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment