forked from rithinskaria/AZ-104
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab-infra.ps1
53 lines (44 loc) · 1.57 KB
/
lab-infra.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
Clear-Host
#Variables
$rg = read-host "(new) Resource Group Name"
$region = "eastus"
$username = "kodekloud" #username for the VM
$plainPassword = "VMP@55w0rd" #your VM password
#Creating VM credential; use your own password and username by changing the variables if needed
$password = ConvertTo-SecureString $plainPassword -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $password);
#Create RG
New-AzResourceGroup -n $rg -l $region
#########-----Create resources---------######
#Creating vnet and VMs
Write-Host "Adding subnet configuration" `
-ForegroundColor "Yellow" -BackgroundColor "Black"
$workloads = New-AzVirtualNetworkSubnetConfig `
-Name 'privateSubnet' `
-AddressPrefix 10.0.0.0/24
New-AzVirtualNetwork `
-ResourceGroupName $rg `
-Location $region `
-Name "prod-eus-vnet" `
-AddressPrefix 10.0.0.0/16 `
-Subnet $workloads
Write-Host "Creating Linux VM" -ForegroundColor "Yellow" -BackgroundColor "Black"
$linuxVm = New-AzVM -Name 'linux-prod-server' `
-ResourceGroupName $rg `
-Location $region `
-Size 'Standard_B1s' `
-Image UbuntuLTS `
-VirtualNetworkName prod-eus-vnet `
-SubnetName 'privateSubnet' `
-Credential $credential
$windowsVm = New-AzVM -Name 'win-prod-server' `
-ResourceGroupName $rg `
-Location $region `
-Size 'Standard_D2s_v3' `
-VirtualNetworkName prod-eus-vnet `
-SubnetName 'privateSubnet' `
-Credential $credential
$fqdn = $linuxVm.FullyQualifiedDomainName
Write-Host "Linux VM DNS name : $fqdn "
$fqdn = $windowsVm.FullyQualifiedDomainName
Write-Host "Windows VM DNS name : $fqdn "