Skip to content

Instantly share code, notes, and snippets.

@santisq
Created January 9, 2022 16:25
Show Gist options
  • Select an option

  • Save santisq/6109cb1ec65e02cbe3810c70d1b155b1 to your computer and use it in GitHub Desktop.

Select an option

Save santisq/6109cb1ec65e02cbe3810c70d1b155b1 to your computer and use it in GitHub Desktop.
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Collections
using namespace System.Collections.Generic
class Completer : IArgumentCompleter {
[IEnumerable[CompletionResult]] CompleteArgument(
[string]$CommandName,
[string]$ParameterName,
[string]$WordToComplete,
[CommandAst]$CommandAst,
[IDictionary]$FakeBoundParameters
) {
$result = [List[CompletionResult]]::new()
DateTimeSpan | Where-Object { $_ -like "*$wordToComplete*" } | ForEach-Object {
$result.Add(
[CompletionResult]::new(
"'$_'", $_, [CompletionResultType]::ParameterValue, $_
)
)
}
return $result
}
}
function DateTimeSpan {
param(
[datetime]$Date
)
$start = [datetime]::now
$end = [datetime]::now.AddDays(1)
$timespan = for($i = $start; $i -lt $end; $i = $i.AddHours(1))
{
$i.ToString()
}
$timespan
}
function Test-ArgumentCompleter {
param(
[ArgumentCompleter([Completer])]
$Test
)
$Test
}
Test-ArgumentCompleter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment