Created
September 28, 2016 18:31
-
-
Save bielawb/1d7feec1ee145fd58737270bfe7a8e8d to your computer and use it in GitHub Desktop.
Using TabExpansionPlusPlus to tab-complete CName -> HostName
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
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