Hello @Kalaimani Thirupathi ,
Thanks for your query.
In order to interact with unmanaged blobs you will have to rely on Azure (not AzureRM) classic powershell CMDlet's
You can install by :
Install-Module Azure -AllowClobber
Can you try using the below sample code to get the snap shot of a blob (Then based upon that you can expand it further)
$storageContext = New-AzureStorageContext -StorageAccountName "saname" -StorageAccountKey storageaccountkey
$blobRef = Get-AzureStorageBlob -Context $storageContext-Container ContainerName -blob BlobName
$snapshots = ($blob.ICloudBlob).Snapshot() //It will list out the snap shots
I just did a sample run through of those commands and example outputs below are from one of my storage account:
PS C:\azure> $snapshots = ($blob.ICloudBlob).Snapshot()
ServiceClient : Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient
StreamMinimumReadSizeInBytes : 4194304
Properties : Microsoft.WindowsAzure.Storage.Blob.BlobProperties
Metadata : {}
Uri : https://shclassic.blob.core.windows.net/vhd/aspnet.yml
StorageUri : Primary = 'https://shclassic.blob.core.windows.net/vhd/aspnet.yml'; Secondary = ''
SnapshotTime : 2/8/2021 11:15:26 PM +00:00
IsSnapshot : True
IsDeleted : False
SnapshotQualifiedUri : https://shclassic.blob.core.windows.net/vhd/aspnet.yml?snapshot=2021-02-08T23:15:26.1385889Z
SnapshotQualifiedStorageUri : Primary = 'https://shclassic.blob.core.windows.net/vhd/aspnet.yml?snapshot=2021-02-08T23:15:26.1385889Z'; Secondary = ''
CopyState :
Name : aspnet.yml
Container : Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
Parent : Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory
BlobType : BlockBlob
Additional References:
- https://www.francoisdelport.com/tag/azure-storage/
- https://superwidgets.wordpress.com/2019/01/02/unmanaged-azure-disk-snapshot-functions-added-to-azsbtools-powershell-module-to-view-add-delete/ (Commands referenced here might need additional CMD let's installation)
Try to modify the below code accordingly
Below module will list out all the UnManaged Disks , tweak the code in TODO section
Function ListAllUnManagedDisks()
{
#initialize the subscriptionid
$subID = "SubID"
#login to Azure Account
Connect-AzAccount
#Get all Azure storage accounts under the subscription
$AllStorageAccounts = Get-AzStorageAccount
#Loop through each storage account
Write-Host "Looping through all the Storage Accounts under the subscription"
foreach($stAcc in $AllStorageAccounts)
{
#Get the Storage account details under the resource group
$strAccount = Get-AzStorageAccount -ResourceGroupName $stAcc.ResourceGroupName -Name $stAcc.StorageAccountName
#Get the context
$context = $strAccount.Context
#Get the Container
$Containers = Get-AzStorageContainer -Context $context
#Loop through all the containers
foreach($container in $containers)
{
#Get all the blobs in the container
$blobData = Get-AzStorageblob -Container $container.Name -Context $context
#Loop through the blobs
foreach($blob in $blobData)
{
#Check if the blob has file with .vhd extension (any blob with extension .vhd considered as UnManaged disk)
if ($blob.Name.ToString().Contains(".vhd"))
{
Write-host "StorageAccountName:" $stAcc.StorageAccountName
Write-host "ContainerName:" $container.Name
Write-host "BlobName:" $blob.Name
#TODO: Try to add above 3 lines of piece of code here ;
}
}
}
}
}
If the above code helps out , kindly "Accept the Answer" so that it will help community out there