-
Notifications
You must be signed in to change notification settings - Fork 58
/
VMSS-Domain-Join.ps1
48 lines (42 loc) · 1.07 KB
/
VMSS-Domain-Join.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
[CmdletBinding()]
param (
$DomainName,
$DomainArmUserName,
$DomainArmPass,
$OUPath,
$ResourceGroup,
$ScaleSetObject
)
Write-Host "Join the VMSS instances to $DomainName ...";
$domainJoinName = "vmssjoindomain"
# JoinOptions.NETSETUP_JOIN_DOMAIN | JoinOptions.NETSETUP_ACCT_CREATE
$Settings = @{
"Name" = $DomainName;
"User" = $DomainArmUserName;
"Restart" = "true";
"Options" = 3;
"OUPath" = $OUPath;
}
$ProtectedSettings = @{
"Password" = $DomainArmPass
}
try {
Remove-AzVmssExtension `
-VirtualMachineScaleSet $ScaleSetObject `
-Name $domainJoinName `
-ErrorAction SilentlyContinue | Out-Null
}
catch {
Write-Host "Remove existing domain join extension failed. Ignore if it is VMSS creation.";
Write-Host "Error info: $_"
}
Add-AzVmssExtension `
-VirtualMachineScaleSet $ScaleSetObject `
-Publisher "Microsoft.Compute" `
-Type "JsonADDomainExtension" `
-TypeHandlerVersion 1.3 `
-Name $domainJoinName `
-Setting $Settings `
-ProtectedSetting $ProtectedSettings `
-AutoUpgradeMinorVersion $true `
-Verbose | Out-Null