# Proxy Function - extending through existing parameters

**URL:** <https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522>\
**Category:** PowerShell Help\
**Created:** [November 13, 2016, 6:17pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522 "2016-11-13T18:17:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wei-yen-tan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/wei-yen-tan/32/91_2.png) [@wei-yen-tan](https://forums.powershell.org/u/wei-yen-tan)\
**Post date:** [November 13, 2016, 6:17pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522/1 "2016-11-13T18:17:07Z")

</div>

Hi Guys,

During my study with PowerShell I was seeking to extend the way the Invoke-Pester works to customize for my company.

I saw Don Jones (many thanks to you btw) earlier tutorials on how to extend existing cmdlets through the use of Proxy Functions. It was exactly what I was looking for.

The goal is to pass parameters to Invoke-Pester but have it shortened to Parameters. I saw June’s example of passing parameters to Pester using a hashtable and the script parameter. (URL link [here](https://www.sapien.com/blog/2016/06/17/how-to-pass-parameters-to-a-pester-test-script/))

I would like something like this:

Invoke-DCoastest -path ‘c:\test\server01.tests.ps1’ -computername ‘server01’ -ipaddress ‘192.168.1.200’ -primarydns ‘192.168.1.203’ -secondarydns ‘192.168.1.204’ -VMWareToolsVer ‘9.1234.123’ -timeserver ‘192.168.1.209’

I have given a shot and come up with the below:

**$scriptCmd = {& $wrappedCmd @PSBoundParameters -Script @{ Path = $path; Parameters = @{ computername = $computername; ipaddress = $ipaddress; primarydns = $primarydns; secondarydns = $secondarydns; timeserver = $timeserver; VMwareToolsVer = $VMWareToolsVer } } }**

However for some reason the way I am passing the parameters doesn’t look right.  
I would appreciate some feedback to see if I have got it right.

```
Function Invoke-DCoatest{
    [CmdletBinding(DefaultParameterSetName = 'LegacyOutputXml')]
    param
    (
	    [Parameter(Position = 0)]
	    [Alias('Path', 'relative_path')]
	    [System.Object[]]$Script,
	    [Parameter(Position = 1)]
	    [Alias('Name')]
	    [string[]]$TestName,
	    [Parameter(Position = 2)]
	    [switch]$EnableExit,
	    [Parameter(ParameterSetName = 'LegacyOutputXml',
				      Position = 3)]
	    [string]$OutputXml,
	    [Parameter(Position = 4)]
	    [Alias('Tags')]
	    [string[]]$Tag,
	    [string[]]$ExcludeTag,
	    [switch]$PassThru,
	    [System.Object[]]$CodeCoverage,
	    [switch]$Strict,
	    [Parameter(ParameterSetName = 'NewOutputSet',
				      Mandatory = $true)]
	    [string]$OutputFile,
	    [Parameter(ParameterSetName = 'NewOutputSet')]
	    [ValidateSet('LegacyNUnitXml', 'NUnitXml')]
	    [string]$OutputFormat,
	    [switch]$Quiet,
	    [System.Object]$PesterOption,
	    [Parameter(Mandatory = $true)]
	    [string]$primarydns,
	    [Parameter(Mandatory = $true)]
	    [string]$secondarydns,
	    [Parameter(Mandatory = $true)]
	    [string]$VMWareToolsVer,
	    [Parameter(Mandatory = $true)]
	    [string]$ipaddress,
	    [Parameter(Mandatory = $true)]
	    [string]$computername,
	    [Parameter(Mandatory = $true)]
	    [string]$timeserver
    )

    begin
    {
        $_ipaddress =$ipaddress
        $_computername =$computername
        $_primarydns =$primarydns
        $_secondarydns =$secondarydns
        $_timeserver =$timeserver
        $_VMWareToolsVer=$VMWareToolsVer

        $PSBoundParameters.Remove('ipaddress')
        $PSBoundParameters.Remove('computername')
        $PSBoundParameters.Remove('primarydns')
        $PSBoundParameters.Remove('secondarydns')
        $PSBoundParameters.Remove('timeserver')
        $PSBoundParameters.Remove('VMWareToolsVer')
        try {
            $outBuffer = $null
            if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
            {
                $PSBoundParameters['OutBuffer'] = 1
            }
            $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Invoke-Pester', [System.Management.Automation.CommandTypes]::Function) **$scriptCmd = {& $wrappedCmd @PSBoundParameters -Script @{ Path = $path; Parameters = @{ computername = $computername; ipaddress = $ipaddress; primarydns = $primarydns; secondarydns = $secondarydns; timeserver = $timeserver; VMwareToolsVer = $VMWareToolsVer } } }** $steppablePipeline = $scriptCmd.GetSteppablePipeline()
            $steppablePipeline.Begin($PSCmdlet)
        } catch {
            throw
        }
    }

    process
    {
        try {
            $steppablePipeline.Process($_)
        } catch {
            throw
        }
    }

    end
    {
        try {
            $steppablePipeline.End()
        } catch {
            throw
        }
    }
    
}
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 13, 2016, 6:20pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522/2 "2016-11-13T18:20:05Z")

</div>

I’m not sure what you mean by “pass parameters to Invoke-Pester but have it shortened to Parameters” - can you maybe show an example of what you’d like to do, rather than just the code you’re trying? Without knowing the end goal I’m not sure I understand.

---

<div class="post-metadata">

**Author:** ![wei-yen-tan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/wei-yen-tan/32/91_2.png) [@wei-yen-tan](https://forums.powershell.org/u/wei-yen-tan)\
**Post date:** [November 13, 2016, 6:23pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522/3 "2016-11-13T18:23:57Z")

</div>

Thanks Don for the reply.

Well an example would be like this:

Invoke-DCoastest -path ‘c:\test\server01.tests.ps1’ -computername ‘server01’ -ipaddress ‘192.168.1.200’ -primarydns ‘192.168.1.203’ -secondarydns ‘192.168.1.204’ -VMWareToolsVer ‘9.1234.123’ -timeserver ‘192.168.1.209’

Invoke-DCoatest will be a proxy function of Invoke-Pester.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 13, 2016, 6:36pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522/4 "2016-11-13T18:36:38Z")

</div>

If what you’re doing works, I don’t see anything “wrong” with it just from a read-through. I mean… I’m not sure this is really the intended usage pattern for Pester. I mean, I’m not sure you need a _proxy_ function, right? Why not just write a normal function that accepts some parameters, and then calls Invoke-Pester?

But whatever works for ya ;).

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/proxy-function-extending-through-existing-parameters/7522/5 "2024-05-16T20:40:01Z")

</div>

Closed on May 16, 2024, 8:40pm UTC


