Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
####
#### Proxy function to restore Writing the URI to verbose when calling Invoke-RestMethod
#### When calling out of a module -Verbose isn't inherited so the function fiddles verbosepreference as a parameter.
Function Invoke-RestMethod {
[CmdletBinding(DefaultParameterSetName='StandardMethod', HelpUri='https://go.microsoft.com/fwlink/?LinkID=2096706')]
<#
.ForwardHelpTargetName Microsoft.PowerShell.Utility\Invoke-RestMethod
.ForwardHelpCategory Cmdlet
#>
param(
[Parameter(ParameterSetName='StandardMethod')]
[Parameter(ParameterSetName='StandardMethodNoProxy')]
[Microsoft.PowerShell.Commands.WebRequestMethod]
$Method,
[Parameter(ParameterSetName='CustomMethod', Mandatory=$true)]
[Parameter(ParameterSetName='CustomMethodNoProxy', Mandatory=$true)]
[Alias('CM')]
[ValidateNotNullOrEmpty()]
[string]
$CustomMethod,
[Alias('FL')]
[switch]
$FollowRelLink,
[Alias('ML')]
[ValidateRange(1, 2147483647)]
[int]
$MaximumFollowRelLink,
[Alias('RHV')]
[string]
$ResponseHeadersVariable,
[string]
$StatusCodeVariable,
[switch]
$UseBasicParsing,
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[uri]
$Uri,
[Microsoft.PowerShell.Commands.WebRequestSession]
$WebSession,
[Alias('SV')]
[string]
$SessionVariable,
[switch]
$AllowUnencryptedAuthentication,
[Microsoft.PowerShell.Commands.WebAuthenticationType]
$Authentication,
[pscredential]
[System.Management.Automation.CredentialAttribute()]
$Credential,
[switch]
$UseDefaultCredentials,
[ValidateNotNullOrEmpty()]
[string]
$CertificateThumbprint,
[ValidateNotNull()]
[X509Certificate]
$Certificate,
[switch]
$SkipCertificateCheck,
[Microsoft.PowerShell.Commands.WebSslProtocol]
$SslProtocol,
[securestring]
$Token,
[string]
$UserAgent,
[switch]
$DisableKeepAlive,
[ValidateRange(0, 2147483647)]
[int]
$TimeoutSec,
[System.Collections.IDictionary]
$Headers,
[ValidateRange(0, 2147483647)]
[int]
$MaximumRedirection,
[ValidateRange(0, 2147483647)]
[int]
$MaximumRetryCount,
[ValidateRange(1, 2147483647)]
[int]
$RetryIntervalSec,
[Parameter(ParameterSetName='CustomMethodNoProxy', Mandatory=$true)]
[Parameter(ParameterSetName='StandardMethodNoProxy', Mandatory=$true)]
[switch]
$NoProxy,
[Parameter(ParameterSetName='StandardMethod')]
[Parameter(ParameterSetName='CustomMethod')]
[uri]
$Proxy,
[Parameter(ParameterSetName='StandardMethod')]
[Parameter(ParameterSetName='CustomMethod')]
[pscredential]
[System.Management.Automation.CredentialAttribute()]
$ProxyCredential,
[Parameter(ParameterSetName='StandardMethod')]
[Parameter(ParameterSetName='CustomMethod')]
[switch]
$ProxyUseDefaultCredentials,
[Parameter(ValueFromPipeline=$true)]
[System.Object]
$Body,
[System.Collections.IDictionary]
$Form,
[string]
$ContentType,
[ValidateSet('chunked','compress','deflate','gzip','identity')]
[string]
$TransferEncoding,
[string]
$InFile,
[string]
$OutFile,
[switch]
$PassThru,
[switch]
$Resume,
[switch]
$SkipHttpErrorCheck,
[switch]
$PreserveAuthorizationOnRedirect,
[switch]
$SkipHeaderValidation,
[parameter(DontShow=$true)]
$VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference')
)
begin {
Write-Verbose "Calling $uri"
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { $PSBoundParameters['OutBuffer'] = 1 }
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Invoke-RestMethod', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
process {
$steppablePipeline.Process($_) }
end {$steppablePipeline.End()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment