-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathARM - Managed Disk.ps1
133 lines (70 loc) · 2.58 KB
/
ARM - Managed Disk.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
## To Set Verbose output
$PSDefaultParameterValues['*:Verbose'] = $true
# Variables - Common
$location = "eastus2"
$tags = New-Object 'System.Collections.Generic.Dictionary[String,object]'
$tags.Add("environment", "Production") # Production, Staging, QA
$tags.Add("projectName", "Demo Project")
$tags.Add("projectVersion", "1.0.0")
$tags.Add("managedBy", "developer.aashishpatel@gmail.com")
$tags.Add("billTo", "Ashish Patel")
$tags.Add("tier", "Front End") # Front End, Back End, Data
$tags.Add("dataProfile", "Public") # Public, Confidential, Restricted, Internal
$rgShortName = "qweasdzxc"
$rgSuffix = "-rg"
$rgName = "${rgShortName}${rgSuffix}"
<# Disk (Managed) #>
<#
#>
# Variables - Disk (Managed)
$diskShortName = "TEST1"
$diskSuffix = "-DataDisk"
$diskName = "${diskShortName}${diskSuffix}"
$diskSizeGB = 100
<# Create Disk (Managed), if it does not exist #>
Get-AzureRmDisk -Name $diskName -ResourceGroupName $rgName -ErrorVariable isDiskExist -ErrorAction SilentlyContinue `
If ($isDiskExist)
{
Write-Output "Disk (Managed) does not exist"
Write-Verbose "Creating Disk (Managed): {$diskName}"
$diskConfig = New-AzureRmDiskConfig `
-Location $location `
-DiskSizeGB $diskSizeGB `
-CreateOption Empty `
-Tag $tags
$dataDisk = New-AzureRmDisk `
-DiskName $diskName `
-ResourceGroupName $rgName `
-Disk $diskConfig `
}
Else
{
Write-Output "Disk (Managed) exist"
Write-Verbose "Fetching Disk (Managed): {$diskName}"
$dataDisk = Get-AzureRmDisk -Name $diskName -ResourceGroupName $rgName
}
Write-Verbose "Get list of Disks (Managed)"
Write-Output "Disks (Managed)"
Get-AzureRmDisk -ResourceGroupName $rgName `
| Select-Object Name, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap
<#
Get-AzureRmDisk `
| Select-Object Name, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap -GroupBy ResourceGroupName
#>
<#
$diskShortName = "TEST1"
$diskSuffix = "-DataDisk"
$diskName = "${diskShortName}${diskSuffix}"
$rgShortName = "qweasdzxc"
$rgSuffix = "-rg"
$rgName = "${rgShortName}${rgSuffix}"
Write-Verbose "Delete Data Disk: {$diskName}"
$jobDiskDelete = Remove-AzureRmDisk -Name $diskName -ResourceGroupName $rgName -Force -AsJob
$jobDiskDelete
#>
<#
# References
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-manage-data-disk
#>