Completers/Microsoft.AzureRm.Storage.StorageAccountName.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
67
$ScriptBlock = {
        <#
        .SYNOPSIS
        Auto-complete the -StorageAccountName parameter value for Azure Resource Manager (ARM) PowerShell cmdlets.
    
        .NOTES
       
        Created by Trevor Sullivan <trevor@trevorsullivan.net>
        http://trevorsullivan.net
        #>

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

        try {
            $StorageAccountList = Get-AzureRmStorageAccount | Where-Object -FilterScript { $PSItem.StorageAccountName -match $wordToComplete } | ForEach-Object {
                $CompletionText = '{0} -ResourceGroupName {1}' -f $PSItem.StorageAccountName, $PSItem.ResourceGroupName;
                $ToolTip = 'Storage Account "{0}" in "{1}" region.' -f $PSItem.StorageAccountName, $PSItem.Location;
                $ListItemText = '{0} ({1})' -f $PSItem.StorageAccountName, $PSItem.Location;
                $CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue;

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

            return $StorageAccountList;
        }
        catch {
            Write-Host -Message ('Error occurred calling argument completer: {0}' -f $PSItem.Exception.Message);
        }
    };

$ArgumentCompleterList = @(
    @{
        CommandName = @(
            'Add-AzureRMHDInsightStorage'
            'New-AzureRMResourceGroup'
            'New-AzureRMResourceGroupDeployment'
            'New-AzureRMStorageContext'
            'Publish-AzureRMVMDscConfiguration'
            'Remove-AzureRMStorageAccount'
            'Restore-AzureRMBackupItem'
            'Set-AzureRMHDInsightDefaultStorage'
            'Set-AzureRMSqlDatabaseAuditingPolicy'
            'Set-AzureRMSqlServerAuditingPolicy'
            'Set-AzureRMVMCustomScriptExtension'
            'Set-AzureRMVMDscExtension'
            'Test-AzureRMResourceGroupTemplate'
        );
        ParameterName = 'StorageAccountName';
        #Description = 'Complete the -StorageAccountName parameter value for Azure Resource Manager (ARM) cmdlets: Get-AzureRmStorageAccountKey -StorageAccountName <TAB>';
        ScriptBlock = $ScriptBlock;
    };
    @{
        CommandName = @(
            'Get-AzureRmStorageAccountKey'
            'New-AzureRmStorageAccountKey'
            'Get-AzureRmStorageAccount'
            'New-AzureRmStorageAccount'
            'Set-AzureRmStorageAccount'
        );
        ParameterName = 'Name';
        #Description = '';
        ScriptBlock = $ScriptBlock;
    }
)

foreach ($ArgumentCompleter in $ArgumentCompleterList) {
    Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter;
}