Last active
June 28, 2020 18:28
-
-
Save DBremen/ea32b027dc5c3fe5ace555bbfab1066e to your computer and use it in GitHub Desktop.
Custom ArgumentCompleter attribute
This file contains 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
Param( | |
[Parameter(Mandatory)] | |
[ArgumentCompleter( | |
{ | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
$allTimezones = Get-TimeZone -ListAvailable | Group-Object DisplayName -AsHashTable -AsString | |
$allTimezones.GetEnumerator() | Where-Object { $_.Name -like "*${wordToComplete}*" } | | |
Sort-Object { $_.Value.Displayname }-Unique | ForEach-Object { | |
New-Object System.Management.Automation.CompletionResult ( | |
"'$($_.Value.Id)'", | |
$_.Value.DisplayName, | |
'ParameterValue', | |
$_.Value.DisplayName | |
) | |
} | |
} | |
)] | |
[Alias('tz')] | |
$RemoteTimeZone | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment