-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDelete-AzureFileStorageDirectoryRecursive.ps1
More file actions
49 lines (37 loc) · 1.45 KB
/
Copy pathDelete-AzureFileStorageDirectoryRecursive.ps1
File metadata and controls
49 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function RemoveFileDir ([Microsoft.Azure.Storage.File.CloudFileDirectory] $dir, [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext] $ctx)
{
$filelist = Get-AzStorageFile -Directory $dir
foreach ($f in $filelist)
{
if ($f.GetType().Name -eq "CloudFileDirectory")
{
RemoveFileDir $f $ctx #Calling the same unction again. This is recursion.
}
else
{
Remove-AzStorageFile -File $f
}
}
Remove-AzStorageDirectory -Directory $dir
}
#define varibales
$StorageAccountName = "Your Storage account name"
$StorageAccountKey = "Your storage account primary key"
$AzShare = "kunalshare - your azure file share name"
$AzDirectory = "LatestPublish - your directory name under which you want to delete everything; including this directry"
#create primary region storage context
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$ctx.ToString()
#Check for Share Existence
$S = Get-AzStorageShare -Context $ctx -ErrorAction SilentlyContinue|Where-Object {$_.Name -eq $AzShare}
# Check for directory
$d = Get-AzStorageFile -Share $S -ErrorAction SilentlyContinue|select Name
if ($d.Name -notcontains $AzDirectory)
{
# directory is not present; no action to be performed
}
else
{
$dir = Get-AzStorageFile -Share $s -Path $AzDirectory
RemoveFileDir $dir $ctx
}