0

has anyone found a good solution to encrypting the password parameters in Powershell for ServiceNow API?

This is the default version :

`$user = "admin"
$pass = "admin"

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$response = Invoke-WebRequest -Header $headers -Method $method -Uri $uri
`
 

`Then I tried the most common way of encrypting the password using "ConvertTo-SecureString":
`
`# Convert the plain text password to an encrypted secure string
$securePassword = ConvertTo-SecureString '' -AsPlainText -Force

# Convert the encrypted password back to a plain text password
$pass = ConvertFrom-SecureString $securePassword

# Set the username
$username = "admin"
`

But this didnt work. Gave me an unauthorised(401) error.

One method I found that did worked was using CredentialManager but I am hesitant to use it because it is not that secure at all. Anyone here has a better solution? Let me know and thanks for the help

c00kie132
  • 1
  • 1

0 Answers0