Last active
May 3, 2017 03:02
-
-
Save irwins/0fcb1cb6cd666e87bf7a to your computer and use it in GitHub Desktop.
Create Custom Intellisense for AD cmdlets with SearchBase parameter using TabExpansion++ Module
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
<# | |
Author: I.C.A. Strachan | |
Version: | |
Version History: | |
Purpose: Custom Intellisense completion for AD cmdlets with SearchBase parameter | |
ActiveDirectory & TabExpansion++ module is required. | |
Link to Trevor Sullivan's video demonstration: https://goo.gl/0TdWuv | |
#> | |
#region Get AD cmdlets with SearchBase parameter | |
$ADCmdlestWithSearchBase = Get-Command -Module ActiveDirectory | | |
ForEach-Object{ | |
$psItem.Name | | |
Where-Object { | |
(Get-Command $psItem).ParameterSets.Parameters.Name -eq 'SearchBase' | |
} | |
} | |
#endregion | |
#region Configure custom intellisense for AD cmdlets with SearchBase | |
$sbADSearchBase= { | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
$ADPaths = ActiveDirectory\Get-ADOrganizationalUnit -filter * | |
foreach ($ADPath in $ADPaths){ | |
$completionResult =@{ | |
CompletionText = $ADPath.DistinguishedName | |
ToolTip = ('The organization unit DistinguishedName {0}' -f $ADPath.DistinguishedName) | |
ListItemText = $ADPath.Name | |
CompletionResultType = 'ParameterValue' | |
} | |
New-CompletionResult @completionResult | |
} | |
} | |
$tabExpansion = @{ | |
CommandName = $ADCmdlestWithSearchBase | |
ParameterName = 'SearchBase' | |
ScriptBlock = $sbADSearchBase | |
} | |
TabExpansion++\Register-ArgumentCompleter @tabExpansion | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment