Last active
September 12, 2017 12:20
-
-
Save chrisfcarroll/ece0e8f169505707bd8c8cd84679f3ae to your computer and use it in GitHub Desktop.
PowerShell wrapper for Invoke-WebRequest with Proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
$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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
AssemblyName
in theAdd-Type
command comes from(Get-Command Invoke-WebRequest).Parameters.WebSession.ParameterType.AssemblyQualifiedName