Skip to content

Instantly share code, notes, and snippets.

@aetos382
Last active August 3, 2016 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aetos382/78c9b8c450a4e8748b781102027765fa to your computer and use it in GitHub Desktop.
Save aetos382/78c9b8c450a4e8748b781102027765fa to your computer and use it in GitHub Desktop.
function Get-CommonParameter {
[OutputType([Hashtable])]
[CmdletBinding(
SupportsShouldProcess)]
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSShouldProcess', '')]
param(
[Parameter(ValueFromRemainingArguments)]
[PSObject[]] $Dummy)
$commonParameterNames = @()
$commonParameterNames += [System.Management.Automation.Cmdlet]::CommonParameters
$commonParameterNames += [System.Management.Automation.Cmdlet]::OptionalCommonParameters
$commonParameters = @{}
foreach ($name in $commonParameterNames) {
[Object] $val = $null
if ($PSBoundParameters.TryGetValue($name, [ref] $val)) {
$commonParameters[$name] = $val
}
}
return $commonParameters
}
function Hoge {
$commonParameters = Get-CommonParameter @PSBoundParameters
Function-In-Other-Module @commonParameters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment