forked from kenieva/batch-policy-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateInitiative.ps1
54 lines (44 loc) · 1.79 KB
/
CreateInitiative.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
$initiativeDefRootFolder = "$(System.DefaultWorkingDirectory)/Policies/initiative"
$subscriptionName = "$(subscriptionName)"
class InitiativeDef {
[string]$InitiativeName
[string]$InitiativeRulePath
}
function Select-Initiatives {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[System.IO.DirectoryInfo[]]$InitiativeFolders
)
Write-Warning "Processing initiatives"
$initiativeList = @()
foreach ($initiativeDefinition in $InitiativeFolders) {
$initiative = New-Object -TypeName InitiativeDef
$initiative.InitiativeName = $initiativeDefinition.Name
$initiative.InitiativeRulePath = $($initiativeDefinition.FullName + "\policyset.json")
$initiativeList += $initiative
}
return $initiativeList
}
function Add-Initiatives {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[InitiativeDef[]]$Initiatives,
[String]$subscriptionId
)
$initiativeDefList = @()
foreach ($initiative in $Initiatives) {
$initiativeDef = New-AzureRmPolicySetDefinition -Name $initiative.InitiativeName -PolicyDefinition $initiative.InitiativeRulePath -SubscriptionId $subscriptionId -Metadata '{"category":"Pipeline"}'
$initiativeDefList += $initiativeDef
}
return $initiativeDefList
}
$subscriptionId = (Get-AzureRmSubscription -SubscriptionName $subscriptionName).Id
#get list of policy folders
$initiative = Select-Initiatives -InitiativeFolders (Get-ChildItem -Path $initiativeDefRootFolder -Directory)
$initiativeDefinitions = Add-Initiatives -Initiatives $initiative -subscriptionId $subscriptionId
#$initiativeDefsJson = ($initiativeDefinitions | ConvertTo-Json -Depth 10 -Compress)
#Write-Host "##vso[task.setvariable variable=PolicyDefs]$initiativeDefsJson"