-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgtagsreport.ps1
43 lines (31 loc) · 1.23 KB
/
rgtagsreport.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
$results = @()
$TagsAsString = ""
$datetime = Get-Date -Format "yyyyMMddhhmm"
foreach ($sub in Get-AzSubscription) {
Set-AzContext -SubscriptionId $sub.SubscriptionId | Out-Null
Write-Host $sub.Name
foreach ($rg in Get-AzResourceGroup) {
Write-Host "`t" $rg.ResourceGroupName
foreach ($tag in $rg.Tags) {
$Tags = $rg.Tags
#Checkign if tags is null or have value
if ($Tags -ne $null) {
$Tags.GetEnumerator() | % { $TagsAsString += $_.Key + ":" + $_.Value + ";" }
}
else {
$TagsAsString = "NULL"
}
$details = @{
SubscriptionName = $sub.Name
ResourceGroupName = $rg.ResourceGroupName
Tags = $TagsAsString
}
$results += New-Object PSObject -Property $details
#Clearing Variable
$TagsAsString = ""
}
}
}
$OutputPathWithFileName = $OutputCSVFilePath + ".\Tags-" + $datetime + ".csv"
$results | Select-Object -Property SubscriptionName, ResourceGroupName, Tags
$results | Select-Object -Property SubscriptionName, ResourceGroupName, Tags | export-csv -Path $OutputPathWithFileName -NoTypeInformation