Hi,
I have a powershell script that we use for creating new accounts in AD and adding the password to PasswordState. It works OK, but I get an error if someone includes a \ in the title.
Example code
$jsonData = '
{
"PasswordListID":"278",
"Title":"'+ $($Title) +'",
"UserName":"'+$($username)+'",
"Description":"'+$($purpose)+'",
"HeartbeatEnabled":true,
"ValidationScriptID":"7",
"generatepassword":true,
"AccountTypeID":"65",
"ADDomainNetBIOS":"test",
"HeartbeatSchedule":"'+$($date)+'"
}'
$PasswordstateUrl = 'https://passwordstate.xxx.com/winapi/passwords'
$result = Invoke-Restmethod -Method Post -Uri $PasswordstateUrl -ContentType "application/json" -Body $jsonData -UseDefaultCredentials
With this data I get the error below
{
"PasswordListID":"278",
"Title":"test\srvtest",
"UserName":"srvtest12",
"Description":"Test script",
"HeartbeatEnabled":true,
"ValidationScriptID":"7",
"generatepassword":true,
"AccountTypeID":"65",
"ADDomainNetBIOS":"test",
"HeartbeatSchedule":"17:04"
}
Invoke-Restmethod : [{"errors":[{"message":"Invalid API Call"},{"phrase":"Error = Object reference not set to an instance of an object.}]}]
If I remove the \ from the Title then it works
{
"PasswordListID":"278",
"Title":"test srvtest",
"UserName":"srvtest12",
"Description":"Test script",
"HeartbeatEnabled":true,
"ValidationScriptID":"7",
"generatepassword":true,
"AccountTypeID":"65",
"ADDomainNetBIOS":"test",
"HeartbeatSchedule":"17:04"
}
Any ideas how to get around this? I could just do a string replace and remove the \, but is it possible to make this work with the \ included?
Best regards,
Johhny