From ee1acc2b0a3a8e2787390c4fc899ede06260ee09 Mon Sep 17 00:00:00 2001 From: Ayan Date: Thu, 24 Oct 2024 18:40:04 -0500 Subject: [PATCH] AzDisk --- AzDisk.ps1 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 AzDisk.ps1 diff --git a/AzDisk.ps1 b/AzDisk.ps1 new file mode 100644 index 0000000..7767bb4 --- /dev/null +++ b/AzDisk.ps1 @@ -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 \ No newline at end of file