forked from lucabol/DTLCustomImagesLab
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdd-TagsToResources.ps1
35 lines (27 loc) · 1.35 KB
/
Add-TagsToResources.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
param
(
[Parameter(Mandatory=$false, HelpMessage="Configuration File, see example in directory")]
[ValidateNotNullOrEmpty()]
[string] $ConfigFile = "config.csv",
[Parameter(Mandatory=$true, HelpMessage="Pass in any tags to be applied like this: @{'Course'='CyberSecurity';'BillingCode'='12345'}")]
[Hashtable] $tags,
[Parameter(Mandatory=$false, HelpMessage="Also tag the lab's resource group?")]
[bool] $tagLabsResourceGroup = $true
)
$ErrorActionPreference = "Stop"
# Common setup for scripts
. "./Utils.ps1" # Import all our utilities
Import-AzDtlModule # Import the DTL Library
$config = Import-ConfigFile -ConfigFile $ConfigFile # Import all the lab settings from the config file
$configCount = ($config | Measure-Object).Count
# Tag all the labs & associated resources
if ($tags) {
Write-Host "---------------------------------" -ForegroundColor Green
Write-Host "Tagging $configCount lab..." -ForegroundColor Green
$jobs = $config | Add-AzDtlLabTags -tags $tags -tagLabsResourceGroup $tagLabsResourceGroup -AsJob
# If there was nothing to tag, there won't be any jobs
if ($jobs) {
Wait-JobWithProgress -jobs $jobs -secTimeout 3600
}
}
Remove-AzDtlModule # Remove the DTL Library