Register-Argument
Completer
Syntax
Register-ArgumentCompleter
-CommandName <String[]>
-ScriptBlock <ScriptBlock>
[-Native]
[<CommonParameters>]
Register-ArgumentCompleter
[-CommandName <String[]>]
-ParameterName <String>
-ScriptBlock <ScriptBlock>
[<CommonParameters>]
Description
The Register-ArgumentCompleter cmdlet registers a custom argument completer.
Examples
Example 1: Register a custom argument completer
PS C:\> Register-ArgumentCompleter -Native -CommandName powershell -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
echo -- -PSConsoleFile -Version -NoLogo -NoExit -Sta -NoProfile -NonInteractive `
-InputFormat -OutputFormat -WindowStyle -EncodedCommand -File -ExecutionPolicy `
-Command |
Where-Object { $_ -like "$wordToComplete*" } |
Sort-Object |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
PS C:\> Register-ArgumentCompleter -CommandName Get-Command -ParameterName Verb -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Get-Verb "$wordToComplete*" |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.Verb, $_.Verb, 'ParameterValue', ("Group: " + $_.Group))
}
}
This example registers a custom argument completer.
Required Parameters
Specifies the name of the command as an array.
Type: | String[] |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the name of the parameter whose argument is being completed.
Type: | String |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the commands to run. Enclose the commands in braces ( { } ) to create a script block. This parameter is required.
Type: | ScriptBlock |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Optional Parameters
Indicates that the argument completer is for a native command where Windows PowerShell cannot complete parameter names.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Inputs
None
You cannot pipe objects to this cmdlet.
Outputs
None
This cmdlet returns no output.