Delete Azure File Share file using Azure CLI

Introduction

Azure CLI (Command-Line Interface) is a set of command-line tools provided by Microsoft for managing resources in Microsoft Azure, which is a cloud computing platform. Azure CLI allows users to interact with Azure services and resources directly from the command line, making it easier to automate tasks, script workflows, and manage Azure resources efficiently.

Prerequisites

  • Up and running ubuntu 22.04 LTS machine.
  • Basic knowledge in linux commands.
  • Internet connectivity.

You can also get azure cli installation process by using given clink.

In this post, We will show you how to delete Azure File Share file using Azure CLI.

Step 1: Installing PowerShell Module

Install the PowerShell module if not installed in your system, use the given command for the same.

Install-Module -Name Az -AllowClobber -Force

Step 2: Importing PowerShell Module

Import the azure power modules by using given command.

Import-Module Az

Step 3: Connect Azure Account

Connect to your Azure account

Connect-AzAccount

Step 4: Set Variables

Set the azure storage’s variable in order to use the future azure cli commands.

# Variables
$resourceGroupName = "YourResourceGroup"
$storageAccountName = "YourStorageAccount"
$fileShareName = "YourFileShare"
$filePath = "Path/To/Your/File.txt"

Step 4: Get Storage Account Context

Get the storage account context.

$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
$ctx = $storageAccount.Context

Step 5: Deleting Azure Files Files

Execute the following command to delete the azure file share files with path.

Remove-AzStorageFile -Context $ctx -ShareName $fileShareName -Path $filePath

Make sure to replace “YourResourceGroup“, “YourStorageAccount“, “YourFileShare“, and “Path/To/Your/File.txt” with your actual resource group, storage account name, file share name, and file path.

Before running the script, ensure that you have the Azure PowerShell module installed. You can install it using the following command:

Install-Module -Name Az -AllowClobber -Force

This script connects to your Azure account, gets the storage account context, and then deletes the specified file from the Azure File Share. Adjust the variables and file path according to your requirements.

Conclusion

We have successfully deleted Azure File Share file using Azure cli , If you still have questions, please post them in the comments section below.

Author

Delete Azure File Share file using Azure CLI

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top