Last active
January 31, 2023 19:21
-
-
Save infamousjoeg/b219aaa01d76873b6e4b45d60b218445 to your computer and use it in GitHub Desktop.
Create & Delete 100 Test User Accounts in a Test Safe for CyberArk PAM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
$baseURL = Read-Host "Enter the base URL of your CyberArk instance" | |
$authType = Read-Host "Enter the authentication type (CyberArk, LDAP)" | |
$credential = Get-Credential | |
# Connect to CyberArk | |
New-PASSession -BaseURI $baseURL -Credential $credential -type $authType -concurrentSession $true -ErrorAction Stop | |
# Create a new CyberArk Safe | |
Add-PASSafe -SafeName "Test-Safe-Script" -Description "Test Safe" -ManagingCPM PasswordManager -NumberOfDaysRetention 1 -ErrorAction SilentlyContinue | |
# Loop 100 times to create 100 accounts in the new safe with a random password and a random username | |
for ($i = 0; $i -lt 100; $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 "Test-Safe-Script" -Address "example.com" -UserName $username -Password $password -PlatformID "WinDomain" -disableAutoMgmt $true -ErrorAction SilentlyContinue | |
} | |
Close-PASSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
$baseURL = Read-Host "Enter the base URL of your CyberArk instance" | |
$authType = Read-Host "Enter the authentication type (CyberArk, LDAP)" | |
$credential = Get-Credential | |
# Connect to CyberArk | |
New-PASSession -BaseURI $baseURL -Credential $credential -type $authType -concurrentSession $true -ErrorAction Stop | |
# Get all accounts in the Test-Safe-Script safe | |
$accounts = Get-PASAccount -SafeName "Test-Safe-Script" -ErrorAction Stop | |
# Loop through all account IDs and delete them | |
foreach ($account in $accounts) { | |
Remove-PASAccount -AccountID $account.ID -ErrorAction SilentlyContinue | |
} | |
# Create a new CyberArk Safe | |
Remove-PASSafe -SafeName "Test-Safe-Script" -ErrorAction Stop | |
Close-PASSession |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment