I have to write a migration script for Active Directory using PowerShell. This script will update the password of the local admin of server stored in Pleasant Password Server for KeePass.
First I log into the KeePass using my Windows login credentials and then search the server for which the password needs to be updated.
So, skipping the script for above said functionalities I will start from generating the password:
function Generate-Password {
$alphabets = "abcdefghijklmnopqstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#%^*"
$char = for ($i = 0; $i -lt $alphabets.Length; $i++) { $alphabets[$i] }
for ($i = 1; $i -le 16; $i++) {
Write-Host -NoNewline $(Get-Random $char)
if ($i -eq 16) { Write-Host `n }
}
}
$pass = Generate-Password
After a password is generated from the above script I want to update the password for the server which I searched.
For example: Find the attachment for Server Details
I want to change the password for the above searched server by the function Generate-Password
.
For this, I used the REST API method of PPS:
function UpdatePassword {
$update = Invoke-RestMethod -Uri “$KeepassURL/api/v4/rest/credential/$CredentialID/password/$pass” -Headers $headers -Method Put -ContentType ‘application/json’
}
I think I am making some mistakes with the syntax here. How do I pass the generated password ie. $pass
to the invoked REST method?