执行该脚本时没有出现任何错误,但是它没有将帐户添加到我的数据库中。我迷路了-任何建议都会有所帮助。
当前使用PowerShell 5.1
$newAccount = @{
safe = $FullSafe
platformID = $platformID
username = $username
AccountName = $AccountName
password = "abc"
secretType = "key"
secret = ""
platformAccountProperties = {}
DisableAutoMgmt = $disableAutoMgmtReason
DisableAutoMgmtReason = $disableAutoMgmtReason
}
$addAccount = $newAccount | ConvertTo-Json
try{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Uri https://"$Environment"/PasswordVault/ -Method post -Body $addAccount -ContentType 'application/json'
}
catch [Exception]
{
$script:errorMessage = $Result
"Error uploading your account"
}
if(($addAccount.StatusCode -eq "200") -and ($addAccount.StatusDescription.Contains("Account added successfully")))
{
$SuccessAuth = 1
}
elseif(!$errorMessage -eq "")
{
$errorMessage
$SuccessAuth = 0
}
if($SuccessAuth -eq 1){
Write-Host $SuccessAuth
}
else
{
Write-Host 'Unable to get PAM authentication token. Please check username and password'
}
if($SuccessAuth -eq 1){
$AddAccountM = "Account " + $FQDN +" has been stored in PAM tool in safe " + $FullSafe + ". Now the script will trigger password change on this account"
Write-Host $AddAccountM
GetAccountID $device $FQDN
}
else
{
$ADE = "Failed in adding account " + $FQDN +" in PAM tool in safe " + $FullSafe
Write-Host $ADE
}
尽管我以前从未使用过Try,Catch函数,所以我没有收到任何错误消息,因此我不确定是否正确使用了它们。另外,我之前从未使用过Invoke-RestMethod,所以不确定是否使用了所有正确的参数。之后的If语句用于验证帐户是否实际上传。