-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathStartStopAzureSQLVMWithDowngradePremiumDisks.ps1
More file actions
57 lines (41 loc) · 1.49 KB
/
StartStopAzureSQLVMWithDowngradePremiumDisks.ps1
File metadata and controls
57 lines (41 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
53
54
55
56
57
Connect-AzAccount
$ResourceGroupName = "YOUR_VM_RESOURCE_GROUP"
$vmnames = get-AzVM -ResourceGroupName $ResourceGroupName -status
foreach ($vmname in $vmnames)
{
$vms = ((Get-AzVM -ResourceGroupName $ResourceGroupName -VMName $vmname.name -Status).Statuses[1]).Code
if ($vms -eq 'PowerState/running')
{
{
stop-AzVM -ResourceGroupName $ResourceGroupName -Name $vmname.name
}
$vdisks = $vmname.StorageProfile.DataDisks
foreach ($vdisk in $vdisks) {
$d = Get-AzDisk -DiskName $vdisk.Name
if ($d.sku.tier -eq "premium") {
$storageType = 'Standard_LRS'
$d.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$d | Update-AzDisk
}
}
}
}
$ResourceGroupName = "YOUR_VM_RESOURCE_GROUP"
$VM = "YOUR_VM_NAME"
$v=get-AzVM -ResourceGroupName $ResourceGroupName -VMName $VM
$vms=((Get-AzVM -ResourceGroupName $ResourceGroupName -VMName $VM -Status).Statuses[1]).Code
$vdisks=$v.StorageProfile.DataDisks
foreach ($vdisk in $vdisks)
{
$d=Get-AzDisk -DiskName $vdisk.Name
if ($d.sku.tier -eq "standard")
{
$storageType = 'Premium_LRS'
$d.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$d | Update-AzDisk
}
}
if ($vms -ne 'PowerState/running')
{
start-AzVM -ResourceGroupName $ResourceGroupName -Name $VM
}