title: Cannot upload new variable to database; improper use of Invoke-RestMethod?
body: <p>I don't get any errors when I execute this script, however it does not add the account to my database. I'm lost - any suggestions would be helpful. </p>
  
  <p>Currently using PowerShell 5.1</p>
  
  <pre><code>$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
  }
  </code></pre>
  
  <p>I don't receive any error messages, though I've never used the Try, Catch functions before so I'm not entirely sure if I'm using them properly. Also, I have never used Invoke-RestMethod before so I'm unsure if I'm using all the correct parameters. The If statements after are used to authenticate if the account is actually uploaded or not.</p>