Skip to content

Instantly share code, notes, and snippets.

@chrisfcarroll chrisfcarroll/Curl.ps1
Last active Sep 12, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.