-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.ps1
48 lines (42 loc) · 1.79 KB
/
deploy.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
param(
[string] $TemplateUri = 'https://raw.githubusercontent.com/martin77s/DomainLab/main/azuredeploy.json',
[string] $ResourceGroupName = ('domainlab-{0:yyyyMMddHHmm}' -f (Get-Date)),
[string] $Location = 'northeurope',
[string] $Prefix = 'lab',
[ValidatePattern('\.local$')] [string] $DomainName = 'domain1.local',
[string] $AdminUsername = 'vmadmin',
[string] $AdminPwd = 'P@55w0rd!P@55w0rd?',
[int] $NumberOfMemberServers = 2,
[string] $vmSizeDCs = 'Standard_D4s_v3',
[string] $vmSizeMemberServers = 'Standard_D4s_v3'
)
# Understand the public IP address of the machine deploying the template
try {
$publicIp = (Invoke-WebRequest -Uri 'https://api.ipify.org/?format=json').Content | ConvertFrom-Json
$clientAllowedIP = '{0}/32' -f $publicIp.ip
} catch {
$clientAllowedIP = '0.0.0.0/32'
}
# Create the deployment template parameters hashtable
$deploymentParams = @{
TemplateUri = $TemplateUri
ResourceGroupName = $ResourceGroupName
Name = $ResourceGroupName
Force = $true
Verbose = $true
Location = $Location
Prefix = $Prefix
ClientAllowedIP = $clientAllowedIP
DomainName = $DomainName
VmAdminUser = $AdminUsername
VmAdminPassword = ($AdminPwd | ConvertTo-SecureString -AsPlainText -Force)
NumberOfMemberServers = $NumberOfMemberServers
vmSizeDCs = $vmSizeDCs
vmSizeMemberServers = $vmSizeMemberServers
}
# Verify the ResourceGroup exists
if (-not (Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue)) {
New-AzResourceGroup -Name $ResourceGroupName -Location $Location | Out-Null
}
# Run the deployment
New-AzResourceGroupDeployment @deploymentParams