-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy path06_Create Azure_VNet.ps1
64 lines (48 loc) · 1.46 KB
/
06_Create Azure_VNet.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
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
Connect-AzAccount
Get-AzContext
Get-AzSubscription
Set-AzContext -Subscription 83bedf1c-859c-471d-831a-fae20a378f44
#Create a resource group
New-AzResourceGroup -Name myResourceGroup -Location WestEurope
#Create the virtual network
$virtualNetwork = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroup `
-Location WestEurope `
-Name myVirtualNetwork `
-AddressPrefix 192.168.0.0/16
#Add a subnet
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
-Name default `
-AddressPrefix 192.168.0.0/24 `
-VirtualNetwork $virtualNetwork
#Associate the subnet to the virtual network
$virtualNetwork | Set-AzVirtualNetwork
#Create virtual machines
New-AzVm `
-ResourceGroupName "myResourceGroup" `
-Location "WestEurope" `
-VirtualNetworkName "myVirtualNetwork" `
-SubnetName "default" `
-Name "myVm1" `
-AsJob
Get-Job
New-AzVm `
-ResourceGroupName "myResourceGroup" `
-Location "WestEurope" `
-VirtualNetworkName "myVirtualNetwork" `
-SubnetName "default" `
-Name "myVm2"
#Connect to a VM from the internet
Get-AzPublicIpAddress `
-Name myVm1 `
-ResourceGroupName myResourceGroup `
| Select IpAddress
Get-AzPublicIpAddress `
-Name myVm2 `
-ResourceGroupName myResourceGroup `
| Select IpAddress
mstsc /v:13.95.209.251
Remove-AzResourceGroup -Name myResourceGroup -Force