Skip to content

Instantly share code, notes, and snippets.

@JohnRoos
Created May 15, 2020 12:36
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 JohnRoos/9ee7e4109f51431d3269a5cdffbc3110 to your computer and use it in GitHub Desktop.
Save JohnRoos/9ee7e4109f51431d3269a5cdffbc3110 to your computer and use it in GitHub Desktop.
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