Following the release of v7.preview3, there was a blog post showcasing the support of COM objects displaying their method argument names now.
https://devblogs.microsoft.com/powershell/powershell-7-preview-3/
Going further, it would be fantastic if the New-Object cmdlet had intellisense for its COM parameter set like what exists for the TypeName parameter set instead of completing from the PWD. It is a common scenario that I have to run registry queries to see which COM classes are available.
New-Object -ComObject Shell.App<TAB>
Also <C-SPACE> for all options.
As a user-side / workaround, it's possible to add them with Register-ArgumentCompleter as in this profile script; line 13 collects and stores them in a cache file, line 74 adds completion for New-Object -ComObject parameter.
Posting that here shortened as a form of documentation:
if (-not (Test-Path $PSScriptRoot\Cache\CompletionCache.ps1xml)) {
[void](New-Item -Path $PSScriptRoot\Cache -ItemType Directory)
Get-CimInstance -ClassName Win32_ClassicCOMClassSetting -Filter 'VersionIndependentProgId IS NOT NULL' |
Select-Object -Property @(
@{L='ProgId'; E={ $_.VersionIndependentProgId }}
@{L='Caption'; E={ ($_.VersionIndependentProgId, $_.Caption)[!!$_.Caption] }}
) | Export-CliXml $PSScriptRoot\Cache\CompletionCache.ps1xml
}
$script:completionCache = Import-CliXml $PSScriptRoot\Cache\CompletionCache.ps1xml
Register-ArgumentCompleter -CommandName New-Object -ParameterName ComObject -ScriptBlock {
param(
[string]
$CommandName,
[string]
$ParameterName,
[string]
$WordToComplete,
[System.Management.Automation.Language.CommandAst]
$CommandAst,
[System.Collections.IDictionary]
$FakeBoundParameters
)
$script:completionCache.Where{ $_.ProgId -like "$WordToComplete*" }.ForEach{
[Management.Automation.CompletionResult]::new($_.ProgId, $_.ProgId, 'Type', $_.Caption)
}
}
TabExpansionPlusPlus also implements this completion, see this file. Note that many of the other completers in that file should be added to PowerShell.
It's also worth mentioning that having a generic caching mechanism for completions like you'd want for -ComObject would be a valuable addition.
Most helpful comment
TabExpansionPlusPlusalso implements this completion, see this file. Note that many of the other completers in that file should be added to PowerShell.It's also worth mentioning that having a generic caching mechanism for completions like you'd want for
-ComObjectwould be a valuable addition.