Completers/Microsoft.Azure.Storage.StorageContainerName.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
31
32
33
34
35
36
$ArgumentCompleter = @{
        CommandName = @('Get-AzureStorageContainerAcl', 
                    'Get-AzureSiteRecoveryProtectionContainer', 
                    'Get-AzureStorageContainer', 
                    'New-AzureStorageContainer', 
                    'New-AzureStorageContainerSASToken', 
                    'Remove-AzureStorageContainer', 
                    'Set-AzureStorageContainerAcl');
        ParameterName = 'Name';
        #Description = 'Complete the -Name parameter value for Azure cmdlets: Get-AzureStorageContainer -Context $Context -Name <TAB>';
        ScriptBlock = {
        <#
        .SYNOPSIS
        Auto-complete the -Name parameter value for Azure PowerShell storage container cmdlets.

        .NOTES
        Created by Trevor Sullivan <trevor@trevorsullivan.net>
        http://trevorsullivan.net
        #>

        param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

        $ContainerList = Get-AzureStorageContainer -Context $fakeBoundParameter['Context'] | Where-Object -FilterScript { $PSItem.Name -match ${wordToComplete} } | ForEach-Object {
            $CompletionText = $PSItem.Name
            $ToolTip = 'Storage Container "{0}" in "{1}" Storage Account.' -f $PSItem.Name, $fakeBoundParameter['Context'].StorageAccountName
            $ListItemText = '{0} ({1})' -f $PSItem.Name, $fakeBoundParameter['Context'].StorageAccountName
            $CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue

            New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList @($CompletionText, $ListItemText, $CompletionResultType, $ToolTip);
        }

        return $ContainerList
        }
    }


Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter;