Invoke-Restmethod breaks script in PS 4.0
Solution 1:
One thing that sticks out at me is that since you're using HTTPS, I'm sure you must be getting certificate errors since your URL is an IP address.
You need to tell Powershell (the .NET framework, really,) to ignore certificate errors. Or else it will crap out on things such as Invoke-WebRequest.
Try this:
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
It's a custom certificate validation callback that always returns true thereby effectively ignoring certificate problems.
Solution 2:
Probably not an answer to your problem, but another point is that you don't have to construct basic authentication headers yourself:
$secPw = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object PSCredential -ArgumentList $username,$secPw
Invoke-RestMethod -Uri $uri -Method Get -Credential $cred
It's especially useful if you're interactively prompting for credentials because you can just use Get-Credential
and be done with it.