Last active
December 12, 2015 01:08
-
-
Save mwjcomputing/4688957 to your computer and use it in GitHub Desktop.
Adds a force switch to Invoke-RestMethod
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
function Invoke-RestMethod { | |
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=217034')] | |
param( | |
[Microsoft.PowerShell.Commands.WebRequestMethod] | |
${Method}, | |
[Parameter(Mandatory=$true, Position=0)] | |
[ValidateNotNullOrEmpty()] | |
[uri] | |
${Uri}, | |
[Microsoft.PowerShell.Commands.WebRequestSession] | |
${WebSession}, | |
[Alias('SV')] | |
[string] | |
${SessionVariable}, | |
[pscredential] | |
${Credential}, | |
[switch] | |
${UseDefaultCredentials}, | |
[ValidateNotNullOrEmpty()] | |
[string] | |
${CertificateThumbprint}, | |
[ValidateNotNull()] | |
[System.Security.Cryptography.X509Certificates.X509Certificate] | |
${Certificate}, | |
[string] | |
${UserAgent}, | |
[switch] | |
${DisableKeepAlive}, | |
[int] | |
${TimeoutSec}, | |
[System.Collections.IDictionary] | |
${Headers}, | |
[ValidateRange(0, 2147483647)] | |
[int] | |
${MaximumRedirection}, | |
[uri] | |
${Proxy}, | |
[pscredential] | |
${ProxyCredential}, | |
[switch] | |
${ProxyUseDefaultCredentials}, | |
[Parameter(ValueFromPipeline=$true)] | |
[System.Object] | |
${Body}, | |
[string] | |
${ContentType}, | |
[ValidateSet('chunked','compress','deflate','gzip','identity')] | |
[string] | |
${TransferEncoding}, | |
[string] | |
${InFile}, | |
[string] | |
${OutFile}, | |
[switch] | |
${PassThru}, | |
[switch] | |
${Force}) | |
begin | |
{ | |
if ($force) { | |
[Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } | |
} | |
try { | |
$outBuffer = $null | |
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) | |
{ | |
$PSBoundParameters['OutBuffer'] = 1 | |
} | |
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Invoke-RestMethod', [System.Management.Automation.CommandTypes]::Cmdlet) | |
$scriptCmd = {& $wrappedCmd @PSBoundParameters } | |
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) | |
$steppablePipeline.Begin($PSCmdlet) | |
} catch { | |
throw | |
} | |
} | |
process | |
{ | |
try { | |
$steppablePipeline.Process($_) | |
} catch { | |
throw | |
} | |
} | |
end | |
{ | |
try { | |
$steppablePipeline.End() | |
} catch { | |
throw | |
} | |
} | |
<# | |
.ForwardHelpTargetName Invoke-RestMethod | |
.ForwardHelpCategory Cmdlet | |
#> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment