sthArgumentCompleter – a PowerShell module that allows you to manage argument completers registered by Register-ArgumentCompleter cmdlet

Register-ArgumentCompleter cmdlet allows you to register argument completers, both custom and native, but there are no integrated ways to get argument completers registered in the current session or to remove some of them.

sthArgumentCompleter – is a module that allows you to manage argument completers registered by Register-ArgumentCompleter cmdlet.

It contains following functions:

Get-CustomArgumentCompleter – Gets registered custom argument completers.

Get-NativeArgumentCompleter – Gets registered native argument completers.

Get-CustomArgumentCompleterScriptBlock – Gets scriptblock of the registered custom argument completer.

Get-NativeArgumentCompleterScriptBlock – Gets scriptblock of the registered native argument completer.

Remove-CustomArgumentCompleter – Removes specified registered custom argument completers.

Remove-NativeArgumentCompleter – Removes specified registered native argument completers.

Clear-CustomArgumentCompleters – Clears all of the registered custom argument completers.

Clear-NativeArgumentCompleters – Clears all of the registered native argument completers.

How to install it?

You can install sthArgumentCompleter module from PowerShell Gallery:

Install-Module sthArgumentCompleter

Also, you can find it on GitHub:
https://github.com/sethvs/sthArgumentCompleter

How to use it?

Get-CustomArgumentCompleter

Example 1: Get all custom argument completers
The command gets all custom argument completers registered in the current session.

Get-CustomArgumentCompleter

CommandName   ParameterName ScriptBlock
-----------   ------------- -----------
Get-Something Name          …
Do-Something  Action        …
              SomeParameter …

Example 2: Get specified custom argument completers
The command gets specified custom argument completer.

Get-CustomArgumentCompleter -Name Get-Something:Name

CommandName   ParameterName ScriptBlock
-----------   ------------- -----------
Get-Something Name          …

Example 3: Get custom argument completers and expand scriptblocks
The command gets specified custom argument completer and expands its scriptblock.

Get-CustomArgumentCompleter -Name Get-Something:Name -ExpandScriptBlocks

CommandName   ParameterName ScriptBlock
-----------   ------------- -----------
Get-Something Name
                            $names = 'NameOne', 'NameTwo', 'NameThree'

                            foreach ($name in $names)
                            {
                                if ($name -like "$wordToComplete*")
                                {
                                    [System.Management.Automation.CompletionResult]::new($name)
                                }
                            }

Get-NativeArgumentCompleter

Example 1: Get all native argument completers
The command gets all native argument completers registered in the current session.

Get-NativeArgumentCompleter

CommandName    ScriptBlock
-----------    -----------
somecommand    …
anothercommand …

Example 2: Get specified native argument completers
The command gets specified native argument completer.

Get-NativeArgumentCompleter -Name somecommand

CommandName ScriptBlock
----------- -----------
somecommand …

Example 3: Get native argument completers and expand scriptblocks
The command gets specified native argument completer and expands its scriptblock.

Get-NativeArgumentCompleter -Name somecommand -ExpandScriptBlocks

CommandName ScriptBlock
----------- -----------
somecommand
            $arguments = 'ArgumentOne', 'ArgumentTwo', 'ArgumentThree'

            foreach ($argument in $arguments)
            {
                if ($argument -like "$wordToComplete*")
                {
                    [System.Management.Automation.CompletionResult]::new($argument)
                }
            }

Get-CustomArgumentCompleterScriptBlock

Example 1: Get scriptblock of the specified custom argument completer
The command gets scriptblock of the specified custom argument completer.

Get-CustomArgumentCompleterScriptBlock -Name Get-Something:Name

$names = 'NameOne', 'NameTwo', 'NameThree'

foreach ($name in $names)
{
    if ($name -like "$wordToComplete*")
    {
        [System.Management.Automation.CompletionResult]::new($name)
    }
}

Example 2: Get scriptblock of custom argument completer using the pipeline
The command gets scriptblock of the custom argument completer sent through the pipeline.

Get-CustomArgumentCompleter -Name Do-Something:Action | Get-CustomArgumentCompleterScriptBlock

$actions = 'ActionOne', 'ActionTwo'

foreach ($action in $actions)
{
    if ($action -like "$wordToComplete*")
    {
        [System.Management.Automation.CompletionResult]::new($action)
    }
}

Get-NativeArgumentCompleterScriptBlock

Example 1: Get scriptblock of the specified native argument completer
The command gets scriptblock of the specified native argument completer.

Get-NativeArgumentCompleterScriptBlock -Name somecommand

$arguments = 'ArgumentOne', 'ArgumentTwo', 'ArgumentThree'

foreach ($argument in $arguments)
{
    if ($argument -like "$wordToComplete*")
    {
        [System.Management.Automation.CompletionResult]::new($argument)
    }
}

Example 2: Get scriptblock of native argument completer using the pipeline
The command gets scriptblock of the native argument completer sent through the pipeline.

Get-NativeArgumentCompleter -Name anothercommand | Get-NativeArgumentCompleterScriptBlock

$arguments = 'ArgumentOne', 'ArgumentTwo'

foreach ($argument in $arguments)
{
    if ($argument -like "$wordToComplete*")
    {
        [System.Management.Automation.CompletionResult]::new($argument)
    }
}

Remove-CustomArgumentCompleter

Example 1: Remove specified custom argument completer
The command removes specified custom argument completer.

Remove-CustomArgumentCompleter -Name Get-Something:Name

Example 2: Remove custom argument completer using the pipeline
The command removes custom argument completer sent through the pipeline.

Get-CustomArgumentCompleter -Name Do-Something:Action | Remove-CustomArgumentCompleter

Remove-NativeArgumentCompleter

Example 1: Remove specified native argument completer
The command removes specified native argument completer.

Remove-NativeArgumentCompleter -Name somecommand

Example 2: Remove native argument completer using the pipeline
The command removes native argument completer sent through the pipeline.

Get-NativeArgumentCompleter -Name anothercommand | Remove-NativeArgumentCompleter

Clear-CustomArgumentCompleters

Example 1: Clear all of the registered custom argument completers
The command clears all of the registered custom argument completers.

Clear-CustomArgumentCompleters

Clear-NativeArgumentCompleters

Example 1: Clear all of the registered native argument completers
The command clears all of the registered native argument completers.

Clear-NativeArgumentCompleters

More PowerShell modules at:
https://sergeyvasin.com/modules/


Links:
GitHub: https://github.com/sethvs
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s