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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$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;
    }

$ArgumentCompleter = @{
        CommandName = @(
            'Get-AzureStorageContainerAcl', 
            'Get-AzureSiteRecoveryProtectionContainer', 
            'Get-AzureStorageContainer', 
            'New-AzureStorageContainer', 
            'New-AzureStorageContainerSASToken', 
            'Remove-AzureStorageContainer', 
            'Set-AzureStorageContainerAcl'
        );
        ParameterName = 'Name';
        ScriptBlock = $ScriptBlock;
    }

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

$ArgumentCompleter = @{
        ### (Get-Command -Module Azure.Storage -ParameterName Container).ForEach({ "'{0}'," -f $PSItem.Name; }) | Set-Clipboard;
        CommandName = @(
            'Get-AzureStorageContainerAcl',
            'Stop-CopyAzureStorageBlob',
            'Get-AzureStorageBlob',
            'Get-AzureStorageBlobContent',
            'Get-AzureStorageBlobCopyState',
            'Get-AzureStorageContainer',
            'Get-AzureStorageContainerStoredAccessPolicy',
            'New-AzureStorageBlobSASToken',
            'New-AzureStorageContainer',
            'New-AzureStorageContainerSASToken',
            'New-AzureStorageContainerStoredAccessPolicy',
            'Remove-AzureStorageBlob',
            'Remove-AzureStorageContainer',
            'Remove-AzureStorageContainerStoredAccessPolicy',
            'Set-AzureStorageBlobContent',
            'Set-AzureStorageContainerAcl',
            'Set-AzureStorageContainerStoredAccessPolicy',
            'Stop-AzureStorageBlobCopy'
        );
        ParameterName = 'Name';
        ScriptBlock = $ScriptBlock;
    }

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