$authInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$username`:$password"))
$headers = @{"X-Requested-With"="$userAgent";"Authorization"="Basic $authInfo"}
$result = Invoke-Restmethod -Method GET -Uri $uri -headers $headers
OS: Windows Server 2012
PowerShell: v5
DDNS service: Google
Cause: Powershell does not pass the password correctly.
Solution: Encode the user credentials in Base64 and add to request headers.
Credit: https://success.qualys.com/support/s/article/000003066#:~:text=401%20Unauthorized%20means%20that%20the,added%20to%20the%20request%20headers.