Created
May 15, 2020 12:36
-
-
Save JohnRoos/9ee7e4109f51431d3269a5cdffbc3110 to your computer and use it in GitHub Desktop.
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
using namespace System.Management.Automation | |
class ValidCommandsGenerator : IValidateSetValuesGenerator { | |
[string[]] GetValidValues() { | |
$Values = (Get-Command).Name | |
return $Values | |
} | |
} | |
Function New-ProxyFunction { | |
[CmdletBinding()] | |
param ( | |
[parameter(mandatory)] | |
[string]$Name, | |
[parameter(mandatory)] | |
[ValidateSet([ValidCommandsGenerator])] | |
[string]$TargetFunctionName | |
) | |
Process { | |
$TargetFunction = Get-Command $TargetFunctionName | |
$TargetFunctionMetadata = [System.Management.Automation.CommandMetadata]::new($TargetFunction) | |
$ProxyFunctionBody = [System.Management.Automation.ProxyCommand]::Create($TargetFunctionMetadata) | |
$ProxyFunction = "function $Name {`n$ProxyFunctionBody`n}" | |
$ProxyFunction | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment