Skip to content

Instantly share code, notes, and snippets.

@lidopaglia
Created May 26, 2014 22:42
Show Gist options
  • Save lidopaglia/6cfa16e1a6f23b4ba64b to your computer and use it in GitHub Desktop.
Save lidopaglia/6cfa16e1a6f23b4ba64b to your computer and use it in GitHub Desktop.
Description for Test-Params.ps1
<#
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