-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileName .ps1
56 lines (42 loc) · 1.75 KB
/
FileName .ps1
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
49
50
51
52
53
54
55
56
$azStorageAccountName = "xxxxxx" # Name of your storage account
$azStorageAccountKey = "xxxxxxx" # Access key for your storage account
$azContainerName = "xxxxxxxxxxx" # Container name to list your blobs
$outputfile = 'output.csv' # CSV file for export list
$connectionContext = New-AzStorageContext -StorageAccountName $azStorageAccountName -StorageAccountKey $azStorageAccountKey
# Get a list of containers in a storage account
#Get-AzStorageContainer -Name $azContainerName -Context $connectionContext | Select Name
# Get a list of blobs in a container
$allblob = Get-AzStorageBlob -Container $azContainerName -Context $connectionContext
$processrows = [System.Collections.ArrayList]@()
foreach ($item in $allblob)
{
$filetype = ($item.Name.Split("."))[-1]
#Get the File Size
[long]$Length = $item.Length
#Format the File size based on size
If ($Length -ge 1TB) {
$sz = "{0:N2} TB" -f ($Length / 1TB)
}
elseif ($Length -ge 1GB) {
$sz = "{0:N2} GB" -f ($Length / 1GB)
}
elseif ($Length -ge 1MB) {
$sz = "{0:N2} MB" -f ($Length / 1MB)
}
elseif ($Length -ge 1KB) {
$sz = "{0:N2} KB" -f ($Length / 1KB)
}
else {
$sz = "$($Length) bytes"
}
$i = @{
"Name" = $item.Name
"FileType" = $filetype
"Size" = $sz
"LastModified" = $item.LastModified
"ContentType" = $item.ContentType
}
$newrow = New-Object Psobject -Property $i
$processrows.Add($newrow)
}
$processrows | Export-Csv $outputfile -Append -Delimiter '|' -Force -NoTypeInformation