Result difference between Visual Studio Code and Command Line

grajee 371 Reputation points
2021-06-05T04:15:40.203+00:00

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

102652-results.jpg

Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,559 questions
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,529 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 13,366 Reputation points Microsoft Employee Moderator
    2021-06-06T18:56:01.587+00:00

    Hello @grajee ,
    Thanks for your query !
    I just tried running the same script at my end but not able to repro the issue i.e. I am perfectly getting the same output both in VSCode & commandline.
    Can you try to debug to find out where exactly that is being filtered out ?
    Try to execute the same using Windows PowerShell ISE
    Try to execute the same using command line - one line at a time and evaluate the variable values - this way you can see where it is being filtered out [Mainly line number 8 , 11, 14 , 19]

    102670-image.png

    102772-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.