-
Notifications
You must be signed in to change notification settings - Fork 61
/
01_Create_and_manage_VM.ps1
107 lines (83 loc) · 2.71 KB
/
01_Create_and_manage_VM.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
Connect-AzAccount
Get-AzSubscription
Set-AzContext -Subscription ID
#Create resource group
New-AzResourceGroup -Name myResourceGroupVM -Location "westeurope"
$cred = Get-Credential
#Create a VM
New-AzVm `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM" `
-Location "WestEurope" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress" `
-Credential $cred
#Connect to VM
Get-AzPublicIpAddress `
-ResourceGroupName "myResourceGroupVM" | Select IpAddress
mstsc /v:<publicIpAddress>
#Understand marketplace images
Get-AzVMImagePublisher -Location "WestEurope"
Get-AzVMImageOffer `
-Location "WestEurope" `
-PublisherName "MicrosoftWindowsServer"
Get-AzVMImageSku `
-Location "WestEurope" `
-PublisherName "MicrosoftWindowsServer" `
-Offer "WindowsServer"
New-AzVm `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM2" `
-Location "WestEurope" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress2" `
-ImageName "MicrosoftWindowsServer:WindowsServer:2016-Datacenter-with-Containers:latest" `
-Credential $cred `
-AsJob
#Understand VM sizes
Get-AzVMSize -Location "WestEurope"
#Resize a VM
Get-AzVM -ResourceGroupName "myResourceGroupVM"
$vm = Get-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-VMName "myVM"
$vm.HardwareProfile.VmSize = "Standard_DS3_v2"
Update-AzVM `
-VM $vm `
-ResourceGroupName "myResourceGroupVM"
#If the size you want isn't available on the current cluster, the VM needs to be deallocated before the resize operation can occur.
Stop-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM" -Force
$vm = Get-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-VMName "myVM"
$vm.HardwareProfile.VmSize = "Standard_E2s_v3"
Update-AzVM -VM $vm `
-ResourceGroupName "myResourceGroupVM"
Start-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-Name $vm.name
#VM power states
Get-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM" `
-Status | Select @{n="Status"; e={$_.Statuses[1].Code}}
#Management tasks
Stop-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM" -Force
Start-AzVM `
-ResourceGroupName "myResourceGroupVM" `
-Name "myVM"
Remove-AzResourceGroup `
-Name "myResourceGroupVM" `
-Force
#https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-manage-vm