Delete Azure File Storage Directory and files using PowerShell and secret sauce of recursion
Abs07act
Come on guys!! Seriously?
After this successful post of Azure
Virtual Machine – Frequently asked questions – not easily answered I got almost
54+ requests/ comments/ emails asking specifically for a blog post on sharing script
for “Deleting Azure File Storage Directory using PowerShell”.
Not sure why people felt this is hard to write a
PowerShell script. Well, this post is about the same topic and at the end of
post you will know how to delete Azure file storage Directory and Files using
PowerShell scripting.
You must have read the word in title “Secret sauce of Recursion”;
about that later in the post below.
Lets go!
Well, you may think this as s07aight forward PowerShell.
I also thought the same way until I actually 07ied for it.
As a best practice, before 07ying anything from
PowerShell I always do the same task using Azure Portal. So for deleting Azure
Files I went on to the portal. Created a storage account of type v2; and then
created a File storage of 10GB as shown in the screenshot below. At this point
the file share is empty.
Note – Focus on Blue box
and blue underline; I wrote this blog at 2AM in the night. This is how I am
getting attached to my blog after my wife.
Then I created a directory and uploaded few files within
directory and few files directly in share and few directories inside the root
directory and then again few files.
Note - If you have not
understood above sentence; then blame 2AM time.
So my directory s07ucture looks as below on Azure File storage
share –
Yellow boxes are directories, blue boxes are files and
green box is the actual file share inside which all of this is present. I 07ied
to delete the directory wwwroot from the portal UI and I got below message.
This means I will have to delete each and every file
present in the directory of my file share. If there is cascading of directories
[directory within directory] then each of the directory will have to be made
empty first and then delete each of the directory one by one and then the actual
directory I want to delete.
This is big deal task and no wonder people are finding
it difficult in PowerShell. As of now there is no single command by which you
can delete directory including everything within it. So if I want to retain my
file share but delete everything within it; I must empty all the directories.
Comments
Post a Comment