Chapters/proxy-functions/snippets.ps1
# proxy base $cmd = New-Object System.Management.Automation.CommandMetaData (Get-Command ConvertTo-HTML) [System.Management.Automation.ProxyCommand]::Create($cmd) | Out-File ConvertToHTMLProxy.ps1 # result [CmdletBinding(DefaultParameterSetName='Page', HelpUri='http://go.microsoft.com/fwlink/?LinkID=113290', RemotingCapability='None')] param( [Parameter(ValueFromPipeline=$true)] [psobject] ${InputObject}, [Parameter(Position=0)] [System.Object[]] ${Property}, [Parameter(ParameterSetName='Page', Position=3)] [string[]] ${Body}, [Parameter(ParameterSetName='Page', Position=1)] [string[]] ${Head}, [Parameter(ParameterSetName='Page', Position=2)] [ValidateNotNullOrEmpty()] [string] ${Title}, [ValidateNotNullOrEmpty()] [ValidateSet('Table','List')] [string] ${As}, [Parameter(ParameterSetName='Page')] [Alias('cu','uri')] [ValidateNotNullOrEmpty()] [uri] ${CssUri}, [Parameter(ParameterSetName='Fragment')] [ValidateNotNullOrEmpty()] [switch] ${Fragment}, [ValidateNotNullOrEmpty()] [string[]] ${PostContent}, [ValidateNotNullOrEmpty()] [string[]] ${PreContent}) begin { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { $PSBoundParameters['OutBuffer'] = 1 } $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\ConvertTo-Html', [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 Microsoft.PowerShell.Utility\ConvertTo-Html .ForwardHelpCategory Cmdlet #> # modifying function NewConvertTo-HTML { [CmdletBinding(DefaultParameterSetName='Page', HelpUri='http://go.microsoft.com/fwlink/?LinkID=113290', RemotingCapability='None')] param( [Parameter(ValueFromPipeline=$true)] [psobject] ${InputObject}, [Parameter(Position=0)] [System.Object[]] ${Property}, [Parameter(ParameterSetName='Page', Position=3)] [string[]] ${Body}, [Parameter(ParameterSetName='Page', Position=1)] [string[]] ${Head}, [Parameter(ParameterSetName='Page', Position=2)] [ValidateNotNullOrEmpty()] [string] ${Title}, [ValidateNotNullOrEmpty()] [ValidateSet('Table','List')] [string] ${As}, [Parameter(ParameterSetName='Page')] [Alias('cu','uri')] [ValidateNotNullOrEmpty()] [uri] ${CssUri}, [Parameter(ParameterSetName='Fragment')] [ValidateNotNullOrEmpty()] [switch] ${Fragment}, [ValidateNotNullOrEmpty()] [string[]] ${PostContent}, [ValidateNotNullOrEmpty()] [string[]] ${PreContent}) begin { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { $PSBoundParameters['OutBuffer'] = 1 } $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\ConvertTo-Html', [System.Management.Automation.CommandTypes]::Cmdlet) # create our css $css += @' <style> th { color:white; background-color: black;} body { font-family: Calibri; padding: 2px } </style> '@ # was -head specified? if ($PSBoundParameters.ContainsKey('head')) { $PSBoundParameters.head += $css } else { $PSBoundParameters += @{'Head'=$css} } $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 Microsoft.PowerShell.Utility\ConvertTo-Html .ForwardHelpCategory Cmdlet #> } # add a param $PSBoundParameters.Remove('MyNewParam') $scriptCmd = {& $wrappedCmd @PSBoundParameters } # remove a param $PSBoundParameters += @{'RemovedParam'=$MyValue} $scriptCmd = {& $wrappedCmd @PSBoundParameters } |