Dism.ArgumentCompleters.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Dism module Custom Completers ##

#
# .SYNOPSIS
#
# Complete the -FeatureName argument to DISM cmdlets
#
function Dism_WindowsOptionalFeatureNameCompleter
{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    Dism\Get-WindowsOptionalFeature -Online | Where-Object FeatureName -like "$wordToComplete*" | Sort-Object FeatureName | ForEach-Object {
        New-CompletionResult $_.FeatureName "FeatureName '$($_.FeatureName)'"
    }
}


Register-ArgumentCompleter `
    -Command ('Disable-WindowsOptionalFeature','Enable-WindowsOptionalFeature','Get-WindowsOptionalFeature') `
    -Parameter 'FeatureName' `
    -Description 'Complete the -FeatureName argument to DISM cmdlets: Get-WindowsOptionalFeature -FeatureName xps* -Online <TAB>' `
    -ScriptBlock $function:Dism_WindowsOptionalFeatureNameCompleter