Created
May 26, 2014 22:42
-
-
Save lidopaglia/6cfa16e1a6f23b4ba64b to your computer and use it in GitHub Desktop.
Description for Test-Params.ps1
This file contains hidden or 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
<# | |
This Gist was created by ISEGist | |
05/26/2014 18:42:33 | |
#> | |
function Test-BoundParams | |
{ | |
<# | |
.SYNOPSIS | |
Add a parameter with default value to PSBoundParameters | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter()] | |
[String] | |
$Name, | |
[Parameter()] | |
[string[]] | |
$Members = (echo Rza,Gza,U-God,MastaKilla,Raekwon), | |
[Parameter()] | |
[string] | |
$Path | |
) | |
$PSBoundParameters | |
$CommonParams = Write-Output Debug, | |
ErrorAction, | |
ErrorVariable, | |
OutVariable, | |
OutBuffer, | |
PipelineVariable, | |
Verbose, | |
WarningAction, | |
WarningVariable, | |
WhatIf, | |
Confirm | |
$Parameters = $MyInvocation.MyCommand.Parameters | |
$Parameters.GetEnumerator().where({$_.key -notin $PSBoundParameters.Keys -and $_.key -notin $CommonParams}) | foreach { | |
if(($var=Get-Variable $_.Key).Value) | |
{ | |
Write-Verbose "Adding parameter `"$($var.Name)`" with default value `"$($var.value)`" to PSBoundParameters" | |
$PSBoundParameters.Add($var.Name,$var.Value) | |
} | |
} | |
$PSBoundParameters | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment