Skip to content

Instantly share code, notes, and snippets.

@chrisfcarroll
Last active September 12, 2017 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisfcarroll/ece0e8f169505707bd8c8cd84679f3ae to your computer and use it in GitHub Desktop.
Save chrisfcarroll/ece0e8f169505707bd8c8cd84679f3ae to your computer and use it in GitHub Desktop.
PowerShell wrapper for Invoke-WebRequest with Proxy
#
$env:Proxy="http://YOUR-CORPORATE-PROXY-HERE" ;
Add-Type -AssemblyName 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
function curl
{
param(
[Parameter(Mandatory=$true)][string]$Uri,
[Object]$Body,
[String]$ContentType,
[PSCredential]$Credential,
[System.Collections.IDictionary]$Headers,
[String]$InFile,
[Int32]$MaximumRedirection,
[Microsoft.PowerShell.Commands.WebRequestMethod]$Method,
[String]$OutFile,
[String]$SessionVariable,
[Int32]$TimeoutSec,
[String]$TransferEncoding,
[String]$UserAgent,
[ Microsoft.PowerShell.Commands.WebRequestSession]$Session
)
$p=@{ProxyUseDefaultCredentials=$true ; Proxy= $env:Proxy }
$PSBoundParameters.GetEnumerator() | %{ $p.Add( $_.Key, $_.Value) }
Invoke-WebRequest @p
}
@chrisfcarroll
Copy link
Author

chrisfcarroll commented Sep 12, 2017

The AssemblyName in the Add-Type command comes from
(Get-Command Invoke-WebRequest).Parameters.WebSession.ParameterType.AssemblyQualifiedName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment