-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSingle-ADDS.ps1
64 lines (59 loc) · 2.61 KB
/
Single-ADDS.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
55
56
57
58
59
60
61
62
63
64
#建立資源群組ADDS
$resourceGroup = "ADDS"
$location = "Southeast Asia"
$vmName = "ADDS"
New-AzResourceGroup -Name $resourceGroup -Location $location
#建立虛擬網路ADDS-vnet
$virtualNetwork = New-AzVirtualNetwork `
-ResourceGroupName $resourceGroup `
-Location $location `
-Name $vmName-vnet `
-AddressPrefix 172.16.0.0/16
$subnetadds = Add-AzVirtualNetworkSubnetConfig `
-Name adds-subnet `
-AddressPrefix 172.16.1.0/24 `
-VirtualNetwork $virtualNetwork
$subnethostpool = Add-AzVirtualNetworkSubnetConfig `
-Name w365-subnet `
-AddressPrefix 172.16.2.0/24 `
-VirtualNetwork $virtualNetwork
$subnetJump = Add-AzVirtualNetworkSubnetConfig `
-Name AzureBastionSubnet `
-AddressPrefix 172.16.3.0/24 `
-VirtualNetwork $virtualNetwork
$virtualNetwork | Set-AzVirtualNetwork
#建立ADDS VM
$User = "isadmin"
$PWord = ConvertTo-SecureString -String "isadmin@123" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
#Create a public IP address and specify a DNS name
$virtualNetwork = Get-AzVirtualNetwork -Name $vmName-vnet -ResourceGroupName $resourceGroup
$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location `
-Name $vmName-pip -AllocationMethod Static -Sku Standard
$nic = New-AzNetworkInterface -Name $vmName-nic -ResourceGroupName $resourceGroup -Location $location `
-SubnetId $virtualNetwork.Subnets[0].Id -PublicIpAddressId $pip.Id
#Create a virtual machine configuration
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D2_v3 | `
Set-AzVMOperatingSystem -Windows -ComputerName $vmName -Credential $Credential | `
Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2019-Datacenter -Version latest | `
Add-AzVMNetworkInterface -Id $nic.Id
# Create a virtual machine
New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig
#建立Bastion
$publicip = New-AzPublicIpAddress `
-ResourceGroupName $resourceGroup `
-name $vmName-Bation-ip `
-location $location `
-AllocationMethod "Static" `
-Sku Standard
New-AzBastion `
-ResourceGroupName $resourceGroup `
-Name $vmName-Bation `
-PublicIpAddress $publicip `
-VirtualNetworkRgName $resourceGroup `
-VirtualNetworkName $vmName-vnet
# Install ADDS
$PublicSettings = '{"commandToExecute":"powershell Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools -Restart"}'
Set-AzVMExtension -ExtensionName "HyperV" -ResourceGroupName $resourceGroup -VMName $vmName `
-Publisher "Microsoft.Compute" -ExtensionType "CustomScriptExtension" -TypeHandlerVersion 1.4 `
-SettingString $PublicSettings -Location $location