CommandType Name Version Source ---------------------------- Alias Add-GroupMember2.9.2 Carbon Alias Add-GroupMembers2.9.2 Carbon Alias Add-IisDefaultDocument2.9.2 Carbon Alias Add-TrustedHost2.9.2 Carbon Alias Add-TrustedHosts2.9.2 Carbon Alias Assert-AdminPrivilege2.9.2 Carbon Alias Assert-AdminPrivileges2.9.2 Carbon Alias Assert-FirewallConfigurable2.9.2 Carbon Alias Assert-Service2.9.2 Carbon Alias Clear-DscLocalResourceCache2.9.2 Carbon Alias Clear-MofAuthoringMetadata2.9.2 Carbon Alias Clear-TrustedHost2.9.2 Carbon Alias Clear-TrustedHosts2.9.2 Carbon Alias Complete-Job2.9.2 Carbon Alias Complete-Jobs2.9.2 Carbon Alias Compress-Item2.9.2 Carbon Alias ConvertFrom-Base642.9.2 Carbon Alias Convert-SecureStringToString2.9.2 Carbon Alias ConvertTo-Base642.9.2 Carbon Alias ConvertTo-ContainerInheritanceFlags2.9.2 Carbon Alias ConvertTo-FullPath2.9.2 Carbon Alias ConvertTo-InheritanceFlag2.9.2 Carbon Alias ConvertTo-InheritanceFlags2.9.2 Carbon Alias ConvertTo-PropagationFlag2.9.2 Carbon Alias ConvertTo-PropagationFlags2.9.2 Carbon Alias ConvertTo-SecurityIdentifier2.9.2 Carbon Alias Convert-XmlFile2.9.2 Carbon Alias Copy-DscResource2.9.2 Carbon Alias Disable-AclInheritance2.9.2 Carbon Alias Disable-FirewallStatefulFtp2.9.2 Carbon Alias Disable-IEEnhancedSecurityConfiguration2.9.2 Carbon Alias Disable-IisSecurityAuthentication2.9.2 Carbon Alias Disable-NtfsCompression2.9.2 Carbon Alias Enable-AclInheritance2.9.2 Carbon Alias Enable-FirewallStatefulFtp2.9.2 Carbon Alias Enable-IEActivationPermission2.9.2 Carbon Alias Enable-IEActivationPermissions2.9.2 Carbon Alias Enable-IisDirectoryBrowsing2.9.2 Carbon Alias Enable-IisSecurityAuthentication2.9.2 Carbon Alias Enable-IisSsl2.9.2 Carbon Alias Enable-NtfsCompression2.9.2 Carbon Alias Expand-Item2.9.2 Carbon Alias Find-ADUser2.9.2 Carbon Alias Format-ADSearchFilterValue2.9.2 Carbon Alias Format-ADSpecialCharacters2.9.2 Carbon Alias Get-ADDomainController2.9.2 Carbon Alias Get-Certificate2.9.2 Carbon Alias Get-CertificateStore2.9.2 Carbon Alias Get-ComPermission2.9.2 Carbon Alias Get-ComPermissions2.9.2 Carbon Alias Get-ComSecurityDescriptor2.9.2 Carbon Alias Get-DscError2.9.2 Carbon Alias Get-DscWinEvent2.9.2 Carbon Alias Get-FileShare2.9.2 Carbon Alias Get-FileSharePermission2.9.2 Carbon Alias Get-FirewallRule2.9.2 Carbon Alias Get-FirewallRules2.9.2 Carbon Alias Get-Group2.9.2 Carbon Alias Get-HttpUrlAcl2.9.2 Carbon Alias Get-IisApplication2.9.2 Carbon Alias Get-IisAppPool2.9.2 Carbon Alias Get-IisConfigurationSection2.9.2 Carbon Alias Get-IisHttpHeader2.9.2 Carbon Alias Get-IisHttpRedirect2.9.2 Carbon Alias Get-IisMimeMap2.9.2 Carbon Alias Get-IisSecurityAuthentication2.9.2 Carbon Alias Get-IisVersion2.9.2 Carbon Alias Get-IisWebsite2.9.2 Carbon Alias Get-IPAddress2.9.2 Carbon Alias Get-Msi2.9.2 Carbon Alias Get-MsmqMessageQueue2.9.2 Carbon Alias Get-MsmqMessageQueuePath2.9.2 Carbon Alias Get-PathCanonicalCase2.9.2 Carbon Alias Get-PathProvider2.9.2 Carbon Alias Get-PathToHostsFile2.9.2 Carbon Alias Get-PerformanceCounter2.9.2 Carbon Alias Get-PerformanceCounters2.9.2 Carbon Alias Get-Permission2.9.2 Carbon Alias Get-Permissions2.9.2 Carbon Alias Get-PowerShellModuleInstallPath2.9.2 Carbon Alias Get-PowershellPath2.9.2 Carbon Alias Get-Privilege2.9.2 Carbon Alias Get-Privileges2.9.2 Carbon Alias Get-ProgramInstallInfo2.9.2 Carbon Alias Get-RegistryKeyValue2.9.2 Carbon Alias Get-ScheduledTask2.9.2 Carbon Alias Get-ServiceAcl2.9.2 Carbon Alias Get-ServiceConfiguration2.9.2 Carbon Alias Get-ServicePermission2.9.2 Carbon Alias Get-ServicePermissions2.9.2 Carbon Alias Get-ServiceSecurityDescriptor2.9.2 Carbon Alias Get-SslCertificateBinding2.9.2 Carbon Alias Get-SslCertificateBindings2.9.2 Carbon Alias Get-TrustedHost2.9.2 Carbon Alias Get-TrustedHosts2.9.2 Carbon Alias Get-User2.9.2 Carbon Alias Get-WmiLocalUserAccount2.9.2 Carbon Alias Grant-ComPermission2.9.2 Carbon Alias Grant-ComPermissions2.9.2 Carbon Alias Grant-HttpUrlPermission2.9.2 Carbon Alias Grant-MsmqMessageQueuePermission2.9.2 Carbon Alias Grant-MsmqMessageQueuePermissions2.9.2 Carbon Alias Grant-Permission2.9.2 Carbon Alias Grant-Permissions2.9.2 Carbon Alias Grant-Privilege2.9.2 Carbon Alias Grant-ServiceControlPermission2.9.2 Carbon Alias Grant-ServicePermission2.9.2 Carbon Alias Initialize-Lcm2.9.2 Carbon Alias Install-Certificate2.9.2 Carbon Alias Install-Directory2.9.2 Carbon Alias Install-FileShare2.9.2 Carbon Alias Install-Group2.9.2 Carbon Alias Install-IisApplication2.9.2 Carbon Alias Install-IisAppPool2.9.2 Carbon Alias Install-IisVirtualDirectory2.9.2 Carbon Alias Install-IisWebsite2.9.2 Carbon Alias Install-Junction2.9.2 Carbon Alias Install-Msi2.9.2 Carbon Alias Install-Msmq2.9.2 Carbon Alias Install-MsmqMessageQueue2.9.2 Carbon Alias Install-PerformanceCounter2.9.2 Carbon Alias Install-RegistryKey2.9.2 Carbon Alias Install-ScheduledTask2.9.2 Carbon Alias Install-Service2.9.2 Carbon Alias Install-SmbShare2.9.2 Carbon Alias Install-User2.9.2 Carbon Alias Invoke-AppCmd2.9.2 Carbon Alias Invoke-PowerShell2.9.2 Carbon Alias Invoke-WindowsInstaller2.9.2 Carbon Alias Join-IisVirtualPath2.9.2 Carbon Alias Lock-IisConfigurationSection2.9.2 Carbon Alias New-Credential2.9.2 Carbon Alias New-Junction2.9.2 Carbon Alias New-RsaKeyPair2.9.2 Carbon Alias New-TempDir2.9.2 Carbon Alias New-TempDirectory2.9.2 Carbon Alias Protect-Acl2.9.2 Carbon Alias Protect-String2.9.2 Carbon Alias Read-File2.9.2 Carbon Alias Remove-Certificate2.9.2 Carbon Alias Remove-DotNetAppSetting2.9.2 Carbon Alias Remove-EnvironmentVariable2.9.2 Carbon Alias Remove-GroupMember2.9.2 Carbon Alias Remove-HostsEntry2.9.2 Carbon Alias Remove-IisMimeMap2.9.2 Carbon Alias Remove-IniEntry2.9.2 Carbon Alias Remove-Junction2.9.2 Carbon Alias Remove-MsmqMessageQueue2.9.2 Carbon Alias Remove-RegistryKeyValue2.9.2 Carbon Alias Remove-Service2.9.2 Carbon Alias Remove-SslCertificateBinding2.9.2 Carbon Alias Remove-User2.9.2 Carbon Alias Reset-HostsFile2.9.2 Carbon Alias Reset-MsmqQueueManagerID2.9.2 Carbon Alias Resolve-FullPath2.9.2 Carbon Alias Resolve-Identity2.9.2 Carbon Alias Resolve-IdentityName2.9.2 Carbon Alias Resolve-NetPath2.9.2 Carbon Alias Resolve-PathCase2.9.2 Carbon Alias Resolve-RelativePath2.9.2 Carbon Alias Restart-RemoteService2.9.2 Carbon Alias Revoke-ComPermission2.9.2 Carbon Alias Revoke-ComPermissions2.9.2 Carbon Alias Revoke-HttpUrlPermission2.9.2 Carbon Alias Revoke-Permission2.9.2 Carbon Alias Revoke-Privilege2.9.2 Carbon Alias Revoke-ServicePermission2.9.2 Carbon Alias Set-DotNetAppSetting2.9.2 Carbon Alias Set-DotNetConnectionString2.9.2 Carbon Alias Set-EnvironmentVariable2.9.2 Carbon Alias Set-HostsEntry2.9.2 Carbon Alias Set-IisHttpHeader2.9.2 Carbon Alias Set-IisHttpRedirect2.9.2 Carbon Alias Set-IisMimeMap2.9.2 Carbon Alias Set-IisWebsiteID2.9.2 Carbon Alias Set-IisWebsiteSslCertificate2.9.2 Carbon Alias Set-IisWindowsAuthentication2.9.2 Carbon Alias Set-IniEntry2.9.2 Carbon Alias Set-RegistryKeyValue2.9.2 Carbon Alias Set-ServiceAcl2.9.2 Carbon Alias Set-SslCertificateBinding2.9.2 Carbon Alias Set-TrustedHost2.9.2 Carbon Alias Set-TrustedHosts2.9.2 Carbon Alias Split-Ini2.9.2 Carbon Alias Start-DscPullConfiguration2.9.2 Carbon Alias Test-AdminPrivilege2.9.2 Carbon Alias Test-AdminPrivileges2.9.2 Carbon Alias Test-DotNet2.9.2 Carbon Alias Test-DscTargetResource2.9.2 Carbon Alias Test-FileShare2.9.2 Carbon Alias Test-FirewallStatefulFtp2.9.2 Carbon Alias Test-Group2.9.2 Carbon Alias Test-GroupMember2.9.2 Carbon Alias Test-Identity2.9.2 Carbon Alias Test-IisAppPool2.9.2 Carbon Alias Test-IisConfigurationSection2.9.2 Carbon Alias Test-IisSecurityAuthentication2.9.2 Carbon Alias Test-IisWebsite2.9.2 Carbon Alias Test-IPAddress2.9.2 Carbon Alias Test-MsmqMessageQueue2.9.2 Carbon Alias Test-NtfsCompression2.9.2 Carbon Alias Test-OSIs32Bit2.9.2 Carbon Alias Test-OSIs64Bit2.9.2 Carbon Alias Test-PathIsJunction2.9.2 Carbon Alias Test-PerformanceCounter2.9.2 Carbon Alias Test-PerformanceCounterCategory2.9.2 Carbon Alias Test-Permission2.9.2 Carbon Alias Test-PowerShellIs32Bit2.9.2 Carbon Alias Test-PowerShellIs64Bit2.9.2 Carbon Alias Test-Privilege2.9.2 Carbon Alias Test-RegistryKeyValue2.9.2 Carbon Alias Test-ScheduledTask2.9.2 Carbon Alias Test-Service2.9.2 Carbon Alias Test-SslCertificateBinding2.9.2 Carbon Alias Test-TypeDataMember2.9.2 Carbon Alias Test-UncPath2.9.2 Carbon Alias Test-User2.9.2 Carbon Alias Test-WindowsFeature2.9.2 Carbon Alias Test-ZipFile2.9.2 Carbon Alias Uninstall-Certificate2.9.2 Carbon Alias Uninstall-Directory2.9.2 Carbon Alias Uninstall-FileShare2.9.2 Carbon Alias Uninstall-Group2.9.2 Carbon Alias Uninstall-IisAppPool2.9.2 Carbon Alias Uninstall-IisWebsite2.9.2 Carbon Alias Uninstall-Junction2.9.2 Carbon Alias Uninstall-MsmqMessageQueue2.9.2 Carbon Alias Uninstall-PerformanceCounterCategory2.9.2 Carbon Alias Uninstall-ScheduledTask2.9.2 Carbon Alias Uninstall-Service2.9.2 Carbon Alias Uninstall-User2.9.2 Carbon Alias Unlock-IisConfigurationSection2.9.2 Carbon Alias Unprotect-AclAccessRules2.9.2 Carbon Alias Unprotect-String2.9.2 Carbon Alias Write-DscError2.9.2 Carbon Alias Write-File2.9.2 Carbon FunctionAdd-CGroupMember2.9.2Carbon FunctionAdd-CTrustedHost2.9.2Carbon FunctionAssert-CAdminPrivilege2.9.2Carbon FunctionAssert-CFirewallConfigurable2.9.2Carbon FunctionAssert-CService2.9.2Carbon FunctionClear-CDscLocalResourceCache2.9.2Carbon FunctionClear-CMofAuthoringMetadata2.9.2Carbon FunctionClear-CTrustedHost2.9.2Carbon FunctionComplete-CJob2.9.2Carbon FunctionCompress-CItem2.9.2Carbon FunctionConvert-CSecureStringToString2.9.2Carbon FunctionConvert-CXmlFile2.9.2Carbon FunctionConvertFrom-CBase642.9.2Carbon FunctionConvertTo-CBase642.9.2Carbon FunctionConvertTo-CContainerInheritanceFlags2.9.2Carbon FunctionConvertTo-CInheritanceFlag2.9.2Carbon FunctionConvertTo-CPropagationFlag2.9.2Carbon FunctionConvertTo-CSecurityIdentifier2.9.2Carbon FunctionCopy-CDscResource2.9.2Carbon FunctionDisable-CAclInheritance2.9.2Carbon FunctionDisable-CFirewallStatefulFtp2.9.2Carbon FunctionDisable-CIEEnhancedSecurityConfiguration2.9.2Carbon FunctionDisable-CNtfsCompression2.9.2Carbon FunctionEnable-CAclInheritance2.9.2Carbon FunctionEnable-CFirewallStatefulFtp2.9.2Carbon FunctionEnable-CIEActivationPermission2.9.2Carbon FunctionEnable-CNtfsCompression2.9.2Carbon FunctionExpand-CItem2.9.2Carbon FunctionFind-CADUser2.9.2Carbon FunctionFormat-CADSearchFilterValue2.9.2Carbon FunctionGet-CADDomainController2.9.2Carbon FunctionGet-CCertificate2.9.2Carbon FunctionGet-CCertificateStore2.9.2Carbon FunctionGet-CComPermission2.9.2Carbon FunctionGet-CComSecurityDescriptor2.9.2Carbon FunctionGet-CDscError2.9.2Carbon FunctionGet-CDscWinEvent2.9.2Carbon FunctionGet-CFileShare2.9.2Carbon FunctionGet-CFileSharePermission2.9.2Carbon FunctionGet-CFirewallRule2.9.2Carbon FunctionGet-CGroup2.9.2Carbon FunctionGet-CHttpUrlAcl2.9.2Carbon FunctionGet-CIPAddress2.9.2Carbon FunctionGet-CMsi2.9.2Carbon FunctionGet-CMsmqMessageQueue2.9.2Carbon FunctionGet-CMsmqMessageQueuePath2.9.2Carbon FunctionGet-CPathProvider2.9.2Carbon FunctionGet-CPathToHostsFile2.9.2Carbon FunctionGet-CPerformanceCounter2.9.2Carbon FunctionGet-CPermission2.9.2Carbon FunctionGet-CPowerShellModuleInstallPath2.9.2Carbon FunctionGet-CPowershellPath2.9.2Carbon FunctionGet-CPrivilege2.9.2Carbon FunctionGet-CProgramInstallInfo2.9.2Carbon FunctionGet-CRegistryKeyValue2.9.2Carbon FunctionGet-CScheduledTask2.9.2Carbon FunctionGet-CServiceAcl2.9.2Carbon FunctionGet-CServiceConfiguration2.9.2Carbon FunctionGet-CServicePermission2.9.2Carbon FunctionGet-CServiceSecurityDescriptor2.9.2Carbon FunctionGet-CSslCertificateBinding2.9.2Carbon FunctionGet-CTrustedHost2.9.2Carbon FunctionGet-CUser2.9.2Carbon FunctionGet-CWmiLocalUserAccount2.9.2Carbon FunctionGrant-CComPermission2.9.2Carbon FunctionGrant-CHttpUrlPermission2.9.2Carbon FunctionGrant-CMsmqMessageQueuePermission2.9.2Carbon FunctionGrant-CPermission2.9.2Carbon FunctionGrant-CPrivilege2.9.2Carbon FunctionGrant-CServiceControlPermission2.9.2Carbon FunctionGrant-CServicePermission2.9.2Carbon FunctionInitialize-CLcm2.9.2Carbon FunctionInstall-CCertificate2.9.2Carbon FunctionInstall-CDirectory2.9.2Carbon FunctionInstall-CFileShare2.9.2Carbon FunctionInstall-CGroup2.9.2Carbon FunctionInstall-CJunction2.9.2Carbon FunctionInstall-CMsi2.9.2Carbon FunctionInstall-CMsmq2.9.2Carbon FunctionInstall-CMsmqMessageQueue2.9.2Carbon FunctionInstall-CPerformanceCounter2.9.2Carbon FunctionInstall-CRegistryKey2.9.2Carbon FunctionInstall-CScheduledTask2.9.2Carbon FunctionInstall-CService2.9.2Carbon FunctionInstall-CUser2.9.2Carbon FunctionInvoke-CAppCmd2.9.2Carbon FunctionInvoke-CPowerShell2.9.2Carbon FunctionNew-CCredential2.9.2Carbon FunctionNew-CJunction2.9.2Carbon FunctionNew-CRsaKeyPair2.9.2Carbon FunctionNew-CTempDirectory2.9.2Carbon FunctionRead-CFile2.9.2Carbon FunctionRemove-CDotNetAppSetting2.9.2Carbon FunctionRemove-CEnvironmentVariable2.9.2Carbon FunctionRemove-CGroupMember2.9.2Carbon FunctionRemove-CHostsEntry2.9.2Carbon FunctionRemove-CIniEntry2.9.2Carbon FunctionRemove-CJunction2.9.2Carbon FunctionRemove-CRegistryKeyValue2.9.2Carbon FunctionRemove-CSslCertificateBinding2.9.2Carbon FunctionReset-CHostsFile2.9.2Carbon FunctionReset-CMsmqQueueManagerID2.9.2Carbon FunctionResolve-CFullPath2.9.2Carbon FunctionResolve-CIdentity2.9.2Carbon FunctionResolve-CIdentityName2.9.2Carbon FunctionResolve-CNetPath2.9.2Carbon FunctionResolve-CPathCase2.9.2Carbon FunctionResolve-CRelativePath2.9.2Carbon FunctionRestart-CRemoteService2.9.2Carbon FunctionRevoke-CComPermission2.9.2Carbon FunctionRevoke-CHttpUrlPermission2.9.2Carbon FunctionRevoke-CPermission2.9.2Carbon FunctionRevoke-CPrivilege2.9.2Carbon FunctionRevoke-CServicePermission2.9.2Carbon FunctionSet-CDotNetAppSetting2.9.2Carbon FunctionSet-CDotNetConnectionString2.9.2Carbon FunctionSet-CEnvironmentVariable2.9.2Carbon FunctionSet-CHostsEntry2.9.2Carbon FunctionSet-CIniEntry2.9.2Carbon FunctionSet-CRegistryKeyValue2.9.2Carbon FunctionSet-CServiceAcl2.9.2Carbon FunctionSet-CSslCertificateBinding2.9.2Carbon FunctionSet-CTrustedHost2.9.2Carbon FunctionSplit-CIni2.9.2Carbon FunctionStart-CDscPullConfiguration2.9.2Carbon FunctionTest-CAdminPrivilege2.9.2Carbon FunctionTest-CDotNet2.9.2Carbon FunctionTest-CDscTargetResource2.9.2Carbon FunctionTest-CFileShare2.9.2Carbon FunctionTest-CFirewallStatefulFtp2.9.2Carbon FunctionTest-CGroup2.9.2Carbon FunctionTest-CGroupMember2.9.2Carbon FunctionTest-CIdentity2.9.2Carbon FunctionTest-CIPAddress2.9.2Carbon FunctionTest-CMsmqMessageQueue2.9.2Carbon FunctionTest-CNtfsCompression2.9.2Carbon FunctionTest-COSIs32Bit2.9.2Carbon FunctionTest-COSIs64Bit2.9.2Carbon FunctionTest-CPathIsJunction2.9.2Carbon FunctionTest-CPerformanceCounter2.9.2Carbon FunctionTest-CPerformanceCounterCategory2.9.2Carbon FunctionTest-CPermission2.9.2Carbon FunctionTest-CPowerShellIs32Bit2.9.2Carbon FunctionTest-CPowerShellIs64Bit2.9.2Carbon FunctionTest-CPrivilege2.9.2Carbon FunctionTest-CRegistryKeyValue2.9.2Carbon FunctionTest-CScheduledTask2.9.2Carbon FunctionTest-CService2.9.2Carbon FunctionTest-CSslCertificateBinding2.9.2Carbon FunctionTest-CTypeDataMember2.9.2Carbon FunctionTest-CUncPath2.9.2Carbon FunctionTest-CUser2.9.2Carbon FunctionTest-CWindowsFeature2.9.2Carbon FunctionTest-CZipFile2.9.2Carbon FunctionUninstall-CCertificate2.9.2Carbon FunctionUninstall-CDirectory2.9.2Carbon FunctionUninstall-CFileShare2.9.2Carbon FunctionUninstall-CGroup2.9.2Carbon FunctionUninstall-CJunction2.9.2Carbon FunctionUninstall-CMsmqMessageQueue2.9.2Carbon FunctionUninstall-CPerformanceCounterCategory2.9.2Carbon FunctionUninstall-CScheduledTask2.9.2Carbon FunctionUninstall-CService2.9.2Carbon FunctionUninstall-CUser2.9.2Carbon FunctionWrite-CDscError2.9.2Carbon FunctionWrite-CFile2.9.2Carbon FilterProtect-CString2.9.2 Carbon FilterUnprotect-CString2.9.2 Carbon
# define a function without argument completer functionStart-Software { param( [Parameter(Mandatory)] [string] $Path )
Start-Process-FilePath$Path }
# define the code used for completing application paths $code = {
}
# calculate the completion values once, and reuse the values later # store results in a script-global variable $script:applicationCompleter = & { # get registered applications from registry $key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*", "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*"
# 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 ) } } }
# instead of complex code, simply return the cached results when needed $code = { $script:applicationCompleter }
# 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
# 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
[Management.Automation.CompletionResult]::new("'OU=managers,DC=company,DC=local'", "Management", "ProviderItem", "OU where the Management lives") [Management.Automation.CompletionResult]::new("'OU=subtest,OU=test,DC=company,DC=local'", "Experimental", "DynamicKeyword", "Reserved") [Management.Automation.CompletionResult]::new("'OU=External,OU=IT,DC=company,DC=local'", "Help Desk", "ProviderItem", "OU where the Helpdesk people reside")
})] [string] $OU )
"Chosen path: $OU" }
完整代码基本上只创建三个新的CompletionResult对象。每个参数都有四个参数:
自动完成的文字
显示在 IntelliSense 菜单中的文字
IntelliSense 菜单的图标
IntelliSense 菜单的工具提示
您甚至可以控制 IntelliSense 菜单中显示的图标。这些是预定义的图标:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
PS> [Enum]::GetNames([System.Management.Automation.CompletionResultType]) Text History Command ProviderItem ProviderContainer Property Method ParameterName ParameterValue Variable Namespace Type Keyword DynamicKeyword
当您运行此代码然后调用 Get-OU 时,可以按 TAB 键完成 OU X500 路径,也可以按 CTRL + SPACE 打开 IntelliSense 菜单。在菜单内,您会看到所选的图标和友好的文本。选择项目后,将使用 X500 自动完成的文字。