locked
How to delete contents of a Blob container via powershell ? RRS feed

  • Question

  • How to delete contents of a Blob container via powershell ?
    Tuesday, June 4, 2019 5:56 AM

Answers

  • Easiest way to delete through Azure Storage Explorer

    The Remove-AzureStorageBlob cmdlet removes the specified blob from a storage account in Azure.

    This script deletes containers in Azure Blob storage based on a prefix in the container name.

    Remove-AzureStorageContainer

    Note: Try on Azure Portal Cloud shell.

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Tuesday, June 4, 2019 6:28 AM
  • Apologies for the delay! You may try the below mentioned cmdlets for deleting the Files inside the container.

    $StorageContext = New-AzureStorageContext -StorageAccountName 'blo***ge18' -StorageAccountKey '<Storage AccountKey>'
    
    Remove-AzureStorageBlob -Container "<Container name>" -Blob "File name" -Context $StorageContext

    Example 2: Remove a storage blob using the pipeline
    
    PowerShell
    PS C:\>Get-AzureStorageBlob -Container "ContainerName" -Blob "BlobName" | Remove-AzureStorageBlob
    This command uses the pipeline.
    
    Example 3: Remove storage blobs using the pipeline
    PS C:\>Get-AzureStorageContainer -Container container* | Remove-AzureStorageBlob -Blob "BlobName"

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.



    Monday, June 10, 2019 7:19 AM
  • @Vignesh Arvind Sorry for the delay response! 

    The above command will help you in deleting only specific blob. If you need to delete whole container you may refer to the below mentioned PS cmdlets.

    Remove-AzureStorageContainer -Name "<container name>" -Context $StorageContext
    
    Hope this helps you!

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.


    Wednesday, July 3, 2019 7:58 AM

All replies

  • Easiest way to delete through Azure Storage Explorer

    The Remove-AzureStorageBlob cmdlet removes the specified blob from a storage account in Azure.

    This script deletes containers in Azure Blob storage based on a prefix in the container name.

    Remove-AzureStorageContainer

    Note: Try on Azure Portal Cloud shell.

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Tuesday, June 4, 2019 6:28 AM
  • Thanks,

    but i want to delete only the files inside that blob container....is it possible through Azure CLI or PS??

    Tuesday, June 4, 2019 6:38 AM
  • Apologies for the delay! You may try the below mentioned cmdlets for deleting the Files inside the container.

    $StorageContext = New-AzureStorageContext -StorageAccountName 'blo***ge18' -StorageAccountKey '<Storage AccountKey>'
    
    Remove-AzureStorageBlob -Container "<Container name>" -Blob "File name" -Context $StorageContext

    Example 2: Remove a storage blob using the pipeline
    
    PowerShell
    PS C:\>Get-AzureStorageBlob -Container "ContainerName" -Blob "BlobName" | Remove-AzureStorageBlob
    This command uses the pipeline.
    
    Example 3: Remove storage blobs using the pipeline
    PS C:\>Get-AzureStorageContainer -Container container* | Remove-AzureStorageBlob -Blob "BlobName"

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.



    Monday, June 10, 2019 7:19 AM
  • Thanks for Sharing this

    it'll delete complete blobs in the container or only a specific blob will be deleted ??

    Wednesday, June 12, 2019 5:09 AM
  • @Vignesh Arvind Sorry for the delay response! 

    The above command will help you in deleting only specific blob. If you need to delete whole container you may refer to the below mentioned PS cmdlets.

    Remove-AzureStorageContainer -Name "<container name>" -Context $StorageContext
    
    Hope this helps you!

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.


    Wednesday, July 3, 2019 7:58 AM
  • Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Wednesday, July 10, 2019 5:23 AM