Skip to content

Instantly share code, notes, and snippets.

@DBremen
Last active June 28, 2020 18:28
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 DBremen/ea32b027dc5c3fe5ace555bbfab1066e to your computer and use it in GitHub Desktop.
Save DBremen/ea32b027dc5c3fe5ace555bbfab1066e to your computer and use it in GitHub Desktop.
Custom ArgumentCompleter attribute
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