-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmUsingImage.ps1
More file actions
52 lines (38 loc) · 1.49 KB
/
vmUsingImage.ps1
File metadata and controls
52 lines (38 loc) · 1.49 KB
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
#Resource Group Name
$resourceGroup = "webapp"
#Location of the Resources
$location = "centralindia"
#VM Name
$vmName = "ubuntu01"
# Defining credentials
$securePassword = ConvertTo-SecureString 'Trainer@1234' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("trainer", $securePassword)
#Creating Resource Group
New-AzResourceGroup -Name $resourceGroup -Location $location
#Creating ubuntu vm
New-AzVM -ResourceGroupName $resourceGroup -Name $vmName -location $location `
-Image UbuntuLTS -Credential $cred -OpenPorts 22
#Inside the ubuntu
#java -version
#sudo apt update
#sudo apt install openjdk-8-jdk
#Stopping the VM
Stop-AzVM -ResourceGroupName $resourceGroup -Name $vmName -Force
#Generalising the VM
Set-AzVm -ResourceGroupName $resourceGroup -Name $vmName -Generalized
#Get the details of VM
$vm = Get-AzVM -Name $vmName -ResourceGroupName $resourceGroup
#Create Image Configuration
$image = New-AzImageConfig -Location $location -SourceVirtualMachineId $vm.Id
#Image Name
$imageName = "jvm-ubuntu"
#Create New Image
New-AzImage -Image $image -ImageName $imageName -ResourceGroupName $resourceGroup
#Getting the Image details
Get-AzImage -ResourceGroupName $resourceGroup
#VM Name created from Custom Image
$vmNameFromCustom = "jvm-ubuntu01"
New-AzVM -ResourceGroupName $resourceGroup -Name $vmNameFromCustom -location $location `
-Image $imageName -Credential $cred -OpenPorts 22
#To Remove Resource Group
#Remove-AzResourceGroup -Name myResourceGroup