forked from lucabol/DTLCustomImagesLab
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNew-CustomRole.ps1
26 lines (22 loc) · 857 Bytes
/
New-CustomRole.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
[CmdletBinding()]
param
(
[ValidateNotNullOrEmpty()]
[string] $customRoleName = "No VM Creation User",
[ValidateNotNullOrEmpty()]
[string] $ActionFile = ".\NoVMCreationRole.json"
)
$ErrorActionPreference = "Stop"
. "./Utils.ps1"
if(-not (Get-AzRoleDefinition -Name $customRoleName)) {
$tmp = New-TemporaryFile
$text = (Get-Content -Path $ActionFile -ReadCount 0) -join "`n"
$subId = (Get-AzContext).Subscription.Id
Write-Host "Current subId $subId"
$text -replace '__subscription__', $subId | Set-Content -Path $tmp.FullName
# All of the above because someone thought that taking an input file, instead of text, is a good idea
New-AzRoleDefinition -InputFile $tmp.FullName
Write-Host "Created $customRoleName from $($tmp.FullName)"
} else {
Write-Error "Custom Role $customRoleName already present"
}