PowerShell Intellisense: ScriptBlock Handler Parameters

I keep forgetting the names of the parameters that are passed into the ScriptBlock handlers for PowerShell Intellisense (aka. tab-completion / auto-completion). Hence, I’m posting the list of parameters here, along with a simple example.

  • $commandName – the name of the PowerShell command that Intellisense was invoked for.
  • $parameterName – the name of the parameter on the command, that Intellisense was invoked for.
  • $wordToComplete – the text that the user has typed thus far.
  • $commandAst – the Abstract Syntax Tree (AST) of the PowerShell command the user has typed thus far.
  • $fakeBoundParameter – the key-value pairs of the other parameters that have been typed by the user thus far.
$ScriptBlock = {
  param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
  (Get-EC2Volume).VolumeId | Where-Object -FilterScript { $PSItem -match $wordToComplete }
}

Register-ArgumentCompleter -CommandName Remove-EC2Volume -ParameterName VolumeId -ScriptBlock $ScriptBlock