PowerShell Web Cmdlet Proxy Defaults for an Office Session
Add command-specific Proxy defaults to PSDefaultParameterValues, preserve unrelated defaults, and remove the entries when changing environments.
From PowerShell 3.0 onward, PSDefaultParameterValues can supply proxy defaults for repeated web calls:
$PSDefaultParameterValues['Invoke-WebRequest:Proxy'] = 'http://proxy.example:8080'
$PSDefaultParameterValues['Invoke-RestMethod:Proxy'] = 'http://proxy.example:8080'
These assignments preserve unrelated defaults in the dictionary. An explicit Proxy parameter overrides the corresponding default. Keep the keys command-specific rather than matching every similarly named parameter with a wildcard. For a separate public-site session where public intermediaries are permitted, choose a candidate from the HTTP proxy list only with no ProxyCredential or ProxyUseDefaultCredentials defaults or explicit proxy credentials set.
If the proxy uses the current Windows identity, add the corresponding defaults:
$PSDefaultParameterValues['Invoke-WebRequest:ProxyUseDefaultCredentials'] = $true
$PSDefaultParameterValues['Invoke-RestMethod:ProxyUseDefaultCredentials'] = $true
Put the chosen entries in the appropriate profile when future interactive sessions should receive them. For a different network, replace their values or remove the entries owned by this setup:
$PSDefaultParameterValues.Remove('Invoke-WebRequest:Proxy')
$PSDefaultParameterValues.Remove('Invoke-RestMethod:Proxy')
$PSDefaultParameterValues.Remove('Invoke-WebRequest:ProxyUseDefaultCredentials')
$PSDefaultParameterValues.Remove('Invoke-RestMethod:ProxyUseDefaultCredentials')
Removal restores ordinary parameter selection. The cmdlet may still use its supported system or environment configuration; removing a default does not explicitly request a direct connection.