Skip to content

Instantly share code, notes, and snippets.

@irwins
Last active May 3, 2017 03:02
Show Gist options
  • Select an option

  • Save irwins/0fcb1cb6cd666e87bf7a to your computer and use it in GitHub Desktop.

Select an option

Save irwins/0fcb1cb6cd666e87bf7a to your computer and use it in GitHub Desktop.

Revisions

  1. irwins revised this gist Nov 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Set-ADSearchBase-Intellisense.ps1
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ $sbADSearchBase= {
    }

    $tabExpansion = @{
    CommandName = $ADCmdlestWithSearchBase
    CommandName = $ADCmdlestWithSearchBase
    ParameterName = 'SearchBase'
    ScriptBlock = $sbADSearchBase
    }
  2. irwins revised this gist Nov 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Set-ADSearchBase-Intellisense.ps1
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ Version:
    Version History:
    Purpose: Custom Intellisense completion for AD cmdlets with SearchBase parameter
    ActiveDirectory module is required.
    ActiveDirectory & TabExpansion++ module is required.
    Link to Trevor Sullivan's video demonstration: https://goo.gl/0TdWuv
  3. irwins created this gist Nov 16, 2015.
    50 changes: 50 additions & 0 deletions Set-ADSearchBase-Intellisense.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@

    <#
    Author: I.C.A. Strachan
    Version:
    Version History:
    Purpose: Custom Intellisense completion for AD cmdlets with SearchBase parameter
    ActiveDirectory 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