All,
I have a peculiar problem with the below code
# https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-powershell
$ctx = New-AzStorageContext -StorageAccountName 'prescriptiveAnalytics' -StorageAccountKey 'SomeStorageAccountKey'
#$ctx
$title = 'Container Sizes for the Storage Account : ' + $ctx.StorageAccountName
$title
# Get the list of Containers
$containerlist = Get-AzStorageContainer -Context $ctx -Name *
foreach ($l in $containerlist)
{
$files = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $l.name -Path '/' -Recurse -FetchProperty -OutputUserPrincipalName
#$files
if ($files -eq $null) {
$Total | Select-Object @{Name = "Container Name"; Expression={$l.name}}, @{Name = "SizeInBytes"; Expression={0}}, @{Name = "SizeInKB"; Expression={0}}
}
else {
# Get the Sum of Length
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-object?view=powershell-7.1
$Total = $Files | Measure-Object -Property Length -Sum
$Total | Select-Object @{Name = "Container Name"; Expression={$l.name}}, @{Name = "SizeInBytes"; Expression={$_.Sum}}, @{Name = "SizeInKB"; Expression={$_.Sum/1KB}}
}
}
When I run the code in Visual Studio Code, I get the 4 rows as expected but if I run the code from commandline by executing the script file then I don't see the rows containing 0. In both the cases, I'm using Powershell v7.1.3. Any idea why I am seeing this difference?
Thanks,
grajee