Pass a username and password for server authentication

Invoke-WebRequest

  • Performs a HTTP/HTTPS request to the Web.
    This command can only be used through PowerShell.
    More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-webrequest>.
  • Trick copyright: tl;dr; <https://github.com/tldr-pages/tldr>

Invoke-WebRequest -Headers @{ Authorization = "Basic "+ [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("myusername:mypassword")) } {{http://example.com}}

click the source code to copy