Export/Private/Set-TagsOnResource.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
function Global:Set-TagsOnResource {
    <#
    .SYNOPSIS
    ...
     
    .EXAMPLE
    ...
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceGroupName,
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceName,        
        [Parameter(Mandatory = $true)]
        [HashTable]
        $Tags
    )
    process {
        Write-Verbose "Adding Tags to Resource..."
        $Resource = Get-AzResource -ResourceGroupName $ResourceGroupName -Name $ResourceName
        #$Tags.GetEnumerator() | ForEach-Object { $Resource.Tags.Add($_.Key, $_.Value) }
        $Resource | Set-AzResource -Tag $Tags -Force  | Out-Null
        #$Resource | Set-AzResource -Force | Out-Null
        Write-Verbose "Done."
    }
}