Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created September 28, 2016 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bielawb/1d7feec1ee145fd58737270bfe7a8e8d to your computer and use it in GitHub Desktop.
Save bielawb/1d7feec1ee145fd58737270bfe7a8e8d to your computer and use it in GitHub Desktop.
Using TabExpansionPlusPlus to tab-complete CName -> HostName
Register-ArgumentCompleter -ParameterName ComputerName -ScriptBlock {
param(
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameter
)
$record = [System.Net.Dns]::Resolve($wordToComplete)
if ($record) {
$name = $record.HostName -replace '\..*$'
[System.Management.Automation.CompletionResult]::new(
$name,
$name,
[System.Management.Automation.CompletionResultType]::ParameterValue,
"Computer $name with aliases $($record.Aliases -join ', ')"
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment