PowerShell Invoke-RestMethod: Bypass a Proxy for One Request
Use NoProxy in PowerShell 7 or an explicit empty session proxy in Windows PowerShell 5.1.
In PowerShell 7, use the web cmdlet’s explicit switch for a request that should go direct:
Invoke-RestMethod -Uri 'https://example.com/' -NoProxy
NoProxy was introduced in PowerShell 6.0 and cannot be combined with Proxy. Windows PowerShell 5.1 does not expose that switch.
For a 5.1 request, provide a web session with an empty WebProxy:
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.Proxy = New-Object System.Net.WebProxy
Invoke-RestMethod -Uri 'https://example.com/' -WebSession $session
The parameterless WebProxy has no proxy address and bypasses destinations. Keep that session for the requests intended to use this direct policy; another session can retain another route.
Check the process version with $PSVersionTable.PSVersion before selecting the form. These examples leave operating-system proxy preferences unchanged.
Direct routing still requires the destination to be reachable from the machine. In a network where internet access is permitted only through the corporate intermediary, bypassing it can correctly produce a connection failure.