-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAzDisk.ps1
37 lines (26 loc) · 1.43 KB
/
AzDisk.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
#region Copy snapshot to storage any account
$storageAccountName = "ayn"
$storageAccountKey = '<>'
$absoluteUri = 'https://<>.blob.core.windows.net/<>/'
$destContainer = 'vhds'
$blobName = 'server.vhd'
$destContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Start-AzureStorageBlobCopy -AbsoluteUri $absoluteUri -DestContainer $destContainer -DestContext $destContext -DestBlob $blobName
#endregion
#region Copy a managed disk to storage any account
$sas = Grant-AzDiskAccess -ResourceGroupName W10VmRG -DiskName W10D -DurationInSecond 3600 -Access Read
$storageAccountContext = New-AzStorageContext -StorageAccountName diskexport1 -StorageAccountKey '<>'
New-AzStorageContainer -Context $storageAccountContext -Name diskexportcont -Verbose
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer diskexportcont -DestContext $storageAccountContext -DestBlob w10.vhd
$a= Get-AzStorageBlobCopyState -Container diskexportcont -Blob w10.vhd -Context $storageAccountContext
($a.BytesCopied/$a.TotalBytes).ToString("P") #Output: 40.389%
#endregion
#region Expand a vhd
$rgName = 'Infra_VMs'
$vmName = 'A20VL001'
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName
Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName
$vm.StorageProfile.OSDisk.DiskSizeGB = 2048
Update-AzureRmVM -ResourceGroupName $rgName -VM $vm
Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName
#endregion