Skip to content

Commit

Permalink
AzDisk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayanmullick committed Oct 24, 2024
1 parent 28cff98 commit ee1acc2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions AzDisk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

0 comments on commit ee1acc2

Please sign in to comment.