Completers/Microsoft.AzureRm.ResourceLocks.Name.ArgumentCompleters - Copy.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-AzureRmResourceLock',
        'New-AzureRmResourceLock',
        'Remove-AzureRmResourceLock',
        'Set-AzureRmResourceLock'
    );
    ParameterName = 'LockName';
    ScriptBlock = {
        <#
        .SYNOPSIS
        Auto-complete the -LockName parameter value for Azure Resource Manager (ARM) cmdlets.
    
        .NOTES
        Created by Trevor Sullivan <trevor@trevorsullivan.net>
        http://trevorsullivan.net
        http://twitter.com/pcgeek86
        #>

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

        ### Create fresh completion results for Azure virtual machines
        $ItemList = Get-AzureRmResourceLock | Where-Object { $PSItem.Name -match $wordToComplete } | ForEach-Object {
            $CompletionText = '{0} -ResourceGroupName {1}' -f $PSItem.Name, $PSItem.ResourceGroupName;
            $ToolTip = 'Lock named {0} applied to Resource Group {1}' -f $PSItem.ResourceName, $PSItem.ResourceGroupName;
            $ListItemText = '{0} ({1})' -f $PSItem.Name, $PSItem.ResourceGroupName;
            $CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue;

            New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList @($CompletionText, $ListItemText, $CompletionResultType, $ToolTip);
        }
    
        ### Return the completion results
        return $ItemList;
    }
}

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