Vijayaragavan Subbaraj

Change user account Password using powershell

Discussion created by Vijayaragavan Subbaraj on Jan 17, 2020

I am working on a script to change the password of the local Qualys user account using PowerShell and Qualys API. I am able to use a session-based login and logout as well. But API to change the password is not working.




$headers = @{"X-Requested-With"="powershell"}
$baseAPIUrl = "https://qualysurl/api/2.0/fo"
$body = "action=login&username=$qualyspasschangername&password=$qualyspasschangerpassword"


#Login and create an open session - Working

Invoke-RestMethod -Headers $headers -Uri "$baseAPIurl/session/" -Method Post -body $body -SessionVariable websession


#Password Change - Not working


$pwchange=Invoke-RestMethod -Headers $headers -Uri "$qualyspwurl" -Method Post -SessionVariable websession


#Logout - Working

Invoke-RestMethod -Headers $headers -Uri "$baseAPIurl/session/" -Method Post -Body "action=logout" -WebSession $webSession

Also, I was trying to pass credential to create Session and it is not working.

$password_base64 = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($qualyspasschangername, $password_base64)


Invoke-RestMethod -Headers $headers -Uri "$baseAPIurl/session/" -Method Post -credential $creds -SessionVariable websession



Let me know if there is a way to call password change API using Invoke-Restmethod and passing the credential for better security.