CmdID

CmdID / PowerShell / Cmdlets / Register

Register-ArgumentCompleter

Registers a custom argument completer. PowerShell reference

From the PowerShell reference 4 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Registers a custom argument completer. The Register-ArgumentCompleter cmdlet registers a custom argument completer. An argument completer allows you to provide dynamic tab completion, at run time for any command that you specify. When you call this command with the CommandName parameter and without the ParameterName or Native parameters, the command runs as if you specified the Native parameter. This prevents the argument completer from working for PowerShell command parameters. Always specify the ParameterName parameter when you want to register an argument completer for PowerShell commands.

Register-ArgumentCompleter -CommandName <String[]> -ScriptBlock <ScriptBlock> [-Native] [<CommonParameters>]
Register-ArgumentCompleter [-CommandName <String[]>] -ParameterName <String> -ScriptBlock <ScriptBlock> [<CommonParameters>]

Register a custom argument completer

$s = { param( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters ) (Get-TimeZone -ListAvailable).Id | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { "'$_'" } } Register-ArgumentCompleter -CommandName Set-TimeZone -ParameterName Id -ScriptBlock $sIdentify

Add details to your tab completion values

$s = { param( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters ) $services = Get-Service | Where-Object { $_.Status -eq 'Running' -and $_.Name -like "$wordToComplete*" } $services | ForEach-Object { New-Object -Type System.Management.Automation.CompletionResult -ArgumentList @( $_.Name # completionText $_.Name # listItemText 'ParameterValue' # resultType $_.Name # toolTip ) } } Register-ArgumentCompleter -CommandName Stop-Service -ParameterName Name -ScriptBlock $sIdentify

Trips 1 Sigma rule: lowStop Windows Service Via PowerShell Stop-Service by Jakob Weinzettl, oscd.community, Nasreddine Bencherchali (Nextron Systems)

Register a custom Native argument completer

$scriptblock = { param( $wordToComplete, $commandAst, $cursorPosition ) dotnet complete --position $cursorPosition $commandAst.ToString() | ForEach-Object { [System.Management.Automation.CompletionResult]::new( $_, # completionText $_, # listItemText 'ParameterValue', # resultType $_ # toolTip ) } } Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblockIdentify

Its page in the reference: Register-ArgumentCompleter.

Parameters

4 in the PowerShell reference
-CommandNameSpecifies the name of one or more commands to register the argument completer for. This parameter is mandatory for native commands. When you specify this parameter without the ParameterName or Native parameters, the command behaves as if you had specified the Native parameter. When registering argument completers for PowerShell commands, always specify the ParameterName parameter. If you don't specify this parameter, PowerShell registers the argument completer for the specified ParameterName across all PowerShell commands.
-NativeIndicates that the argument completer is for a native command where PowerShell can't complete parameter names.
-ParameterNameSpecifies the name of the parameter the argument completer applies to. The type for specified parameters can't be an enumeration, such as the ForegroundColor parameter of the Write-Host cmdlet. For more information on enums, see about_Enum. When registering an argument completer for PowerShell commands, always specify this parameter. When you specify the CommandName parameter without the ParameterName or Native parameters, the command behaves as if you specified the Native parameter.
-ScriptBlockSpecifies the commands to run to perform tab completion. The scriptblock you provide should return the values that complete the input. The scriptblock must unroll the values using the pipeline (ForEach-Object, Where-Object, etc.), or another suitable method. Returning an array of values causes PowerShell to treat the entire array as one tab completion value. The scriptblock can also return System.Management.Automation.CompletionResult objects for each value to enhance the user experience. Returning CompletionResult objects enables you to define tooltips and custom list entries displayed when users press <kbd>Ctrl</kbd>+<kbd>Space</kbd> to show the list of available completions. The scriptblock must accept the following parameters in the order specified below. The names of the parameters aren't important because PowerShell passes in the values by position. - $commandName (Position 0, String) - This parameter is set to the name of the command for which the scriptblock is providing tab completion. - $parameterName (Position 1, String) - This parameter is set to the parameter whose value requires tab completion. …