Last active
May 17, 2022 17:53
-
-
Save ryanvgates/58fef013ea21e560a3dea79d29410004 to your computer and use it in GitHub Desktop.
PowerShell CyberArk Add Account
This file contains hidden or 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
Add-Type -AssemblyName System.Web | |
Write-Host "$((get-date).ToString()) - Attempting to create account $username on platform $platformID, address $Address in safe $Safename on $CyberArkHost" | |
$Account_URI = "https://$CyberArkHost/PasswordVault/api/Accounts" | |
$AccountHeader = @{'accept'='application/json';'content-type'='application/json';'Authorization'=$Token} | |
$Account_Body="{ | |
""address"":""$address"", | |
""userName"":""$username"", | |
""platformId"":""$platformID"", | |
""safeName"":""$Safename"", | |
""secretType"":""password"", | |
""secret"":""$([System.Web.Security.Membership]::GeneratePassword(20, 10))"", | |
""platformAccountProperties"": { | |
""LogonDomain"": ""HOSTING"" | |
}, | |
""secretManagement"":{ | |
""automaticManagementEnabled"":false | |
}, | |
""remoteMachinesAccess"":{ | |
""accessRestrictedToRemoteMachines"":false } | |
}" | |
$addAccountResponse = Invoke-WebRequest -Uri $Account_URI -Method POST -Body $Account_Body -Headers $AccountHeader -UseBasicParsing | |
if($addAccountResponse.StatusCode -eq 201) | |
{ | |
Write-Host "$((get-date).ToString()) - Successfully created account $username on platform $platformID, address $Address in safe $Safename on $CyberArkHost" -ForegroundColor Green | |
} | |
else | |
{ | |
Write-Host "$((get-date).ToString()) - Failed to create account $username on platform $platformID, address $Address in safe $Safename on $CyberArkHost with response status code $($addAccountResponse.StatusCode) headers $($addAccountResponse.headers) and content $($addAccountResponse.Content)" -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment