# add applications found by Get-Command [System.Collections.Generic.List[string]]$commands = Get-Command-CommandType Application | Select-Object-ExpandProperty Source $list.AddRange($commands)
# add descriptions and compose completionresult entries $list | # remove empty paths Where-Object { $_ } | # remove quotes and turn to lower case ForEach-Object { $_.Replace('"','').Trim().ToLower() } | # remove duplicate paths Sort-Object-Unique | ForEach-Object { # skip files that do not exist if ( (Test-Path-Path$_)) { # get file details $file = Get-Item-Path$_ # quote path if it has spaces $path = $_ if ($path-like'* *') { $path = "'$path'" } # make sure tooltip is not null $tooltip = [string]$file.VersionInfo.FileDescription if ([string]::IsNullOrEmpty($tooltip)) { $tooltip = $file.Name } # compose completion result [Management.Automation.CompletionResult]::new( # complete path $path, # show friendly text in IntelliSense menu ('{0} ({1})'-f$tooltip, $file.Name), # use file icon 'ProviderItem', # show file description $tooltip ) } } }
# tie the completer code to all applicable parameters of own or foreign commands Register-ArgumentCompleter-CommandNameStart-Software-ParameterName Path -ScriptBlock$code Register-ArgumentCompleter-CommandNameStart-Process-ParameterName FilePath -ScriptBlock$code