Created
January 10, 2015 20:37
-
-
Save AndySchneiderDev-zz/b275091e1705f95d171e to your computer and use it in GitHub Desktop.
TabExpansionPlusPlus for AD Users and Groups
This file contains hidden or 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
function ADuserCompletion { | |
[ArgumentCompleter( | |
Parameter = 'Identity', | |
Command = { Get-CommandWithParameter -Module ActiveDirectory -Noun ADUser -ParameterName Identity }, | |
Description = 'Complete AD Users')] | |
param($commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameter) | |
if ($wordToComplete -eq "") {$filter = "(ObjectClass=User)"} | |
else {$filter = "(&(ObjectClass=User)(ANR=$wordToComplete))"} | |
Get-ADuser -LDAPFilter $filter | sort SamAccountname | | |
% {New-CompletionResult -ToolTip $_.SamAccountname -completiontext $_.SamAccountName} | |
} | |
function ADGroupCompletion { | |
[ArgumentCompleter( | |
Parameter = 'Identity', | |
Command = { Get-CommandWithParameter -Module ActiveDirectory -Noun ADGroup -ParameterName Identity }, | |
Description = 'Complete AD Groups')] | |
param($commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameter) | |
if ($wordToComplete -eq "") {$filter = "(ObjectClass=Group)"} | |
else {$filter = "(&(ObjectClass=Group)(ANR=$wordToComplete))"} | |
Get-ADGroup -LDAPFilter $filter | sort SamAccountname | | |
% {New-CompletionResult -ToolTip $_.SamAccountname -completiontext $_.SamAccountName} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment