PoSH Script – Add password to PasswordState

The following was useful for me when automating password rotation along with the PasswordState Password management software.

$pws = "PasswordState API Token"
$jsonData = @"
     {
         "PasswordListID":"123",
         "Title":"Administrator",
         "UserName":"Administrator",
         "password":"$($pword)"
     }
 "@
$PasswordstateUrl = 'https://lonpasswords01.vtom.uk:9119/api/passwords'
$result = Invoke-Restmethod -Method Post -Uri $PasswordstateUrl -ContentType "application/json" -Body $jsonData -Header @{ "APIKey" = "$pws" }
Write-host $result.username $result.passwordID