SmbShare.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
24
25
26
27
28
29
30
#
# .SYNOPSIS
#
# Complete the -Name argument to *SmbShare cmdlets
#
function SmbShareNameParameterCompletion
{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    $optionalCimSession = @{}
    $cimSession = $fakeBoundParameter['CimSession']
    if ($cimSession)
    {
        $optionalCimSession['CimSession'] = $cimSession
    }

    Get-SmbShare -Name "$wordToComplete*" @optionalCimSession |
        Sort-Object Name |
        ForEach-Object {
            New-CompletionResult $_.Name $_.Description
        }
}


Register-ArgumentCompleter `
    -Command ('Get-SmbShare', 'Remove-SmbShare', 'Set-SmbShare','Block-SmbShareAccess','Get-SmbShareAccess','Grant-SmbShareAccess','Revoke-SmbShareAccess','Unblock-SmbShareAccess') `
    -Parameter 'Name' `
    -Description 'Complete share names.' `
    -ScriptBlock $function:SmbShareNameParameterCompletion