none
Azure File Share: Powershell: Getstats() throws Int32 error RRS feed

  • Question

  • Hey all...I'm seeing something odd in Powershell when trying to query space used on Azure file shares. 

    Problem: When calling .GetStats() on an Azure file share where the usage is fairly high, say, more than a few GB, Powershell throws an exception. It's 100% consistent and reproducible. Drop 5-10GB in a share and run $share.getstats() to reproduce the error as follows: 

    Exception calling "GetStats" with "0" argument(s): "Value was either too large or too small for an Int32."
    At line:1 char:1
    + $share.GetStats()
    + ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : StorageException

    I tried GetStats().Usage and Getstats().UsageInBytes. Nope. I've tried dumping the output into different DataTypes. Nope. I tried converting ToInt64(). No dice. 

    Anyone have a suggestion? Looking for a fix or a workaround. I'd hate to resort to querying each file separately and adding the sizes together.

    Thanks!

    Shawn

    Thursday, September 12, 2019 5:53 PM

Answers

  • Thanks for reporting this!

    I can repro the issue in the latest Azure Powershell module.

    This issue is caused by “Microsoft.Azure.Storage.File” library (Powershell based on it). I have tested the API with only latest “Microsoft.Azure.Storage.File” 11.0.1 in VS, and the same failure can repro.

    I will ping the related team to fix the library. And upgrade Powershell after the issue fixed in the library.  Before that, you can check the share usage in Portal.

    BTW, the formal way for Powershell issue is https://github.com/Azure/azure-powershell/issues .

    • Marked as answer by sspat Thursday, September 19, 2019 2:17 PM
    Monday, September 16, 2019 8:16 AM

All replies

  • Thanks for reporting this - what is the PS module version, so I can report it to our PS team.

    As an alternative, you can consider calling the API directly or calling the C# SDK from PS. 

    https://blogs.msdn.microsoft.com/igorpag/2017/06/28/using-powershell-as-an-azure-arm-rest-api-client/

    Thursday, September 12, 2019 8:54 PM
  • Ivo,

    Thank you for your reply.

    Azure Module Version: 5.3.0   (PSVersion: 5.1)

    I appreciate the suggestion on alternatives. In fact, I started working through trying to query Storage Statistics using the REST API earlier today. Figuring out how to build the authorization header has eluded me thus far, but I'll keep plugging away. Thank you!

    Thursday, September 12, 2019 9:44 PM
  • Hi sspat,

    It looks like you're running an older version of the Azure PowerShell cmdlets. The Azure PowerShell team released a new module last year called Az, instead of AzureRM, and it's currently on version 2.6. You can read more information about it here: https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az

    Can you verify you still receive this message with the latest and greatest module? As Ivo said, we will report it to the PS team if you still receive this error after upgrading.

    Thanks,

    Will Gries
    Program Manager, Azure Files


    Friday, September 13, 2019 11:01 AM
  • Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Monday, September 16, 2019 5:47 AM
    Moderator
  • Thanks for reporting this!

    I can repro the issue in the latest Azure Powershell module.

    This issue is caused by “Microsoft.Azure.Storage.File” library (Powershell based on it). I have tested the API with only latest “Microsoft.Azure.Storage.File” 11.0.1 in VS, and the same failure can repro.

    I will ping the related team to fix the library. And upgrade Powershell after the issue fixed in the library.  Before that, you can check the share usage in Portal.

    BTW, the formal way for Powershell issue is https://github.com/Azure/azure-powershell/issues .

    • Marked as answer by sspat Thursday, September 19, 2019 2:17 PM
    Monday, September 16, 2019 8:16 AM
  • Thank you for the update! Yes, I was going to say I did repro this in an Azure Automation Runbook with the latest Az module installed. I appreciate you running it up the chain of command and getting a fix underway. It appears the limit in my testing is 2GB. Anything over 2GB throws the error. 

    Kind regards,

    Shawn

    Tuesday, September 17, 2019 7:35 PM
  • Hi @sspat. I’m also facing the exact same issue. Did you find any workaround or solution for it. Also I found a link mentioned below. Can you please help to use the function mentioned in this link in powershell. https://azure.github.io/azure-storage-java/com/microsoft/azure/storage/file/ShareStats.html#ShareStats()
    Wednesday, September 18, 2019 2:40 AM
  • Glad to learn I'm not the only one facing this. Per the above, I think the best solution is to use REST API to pull usage data, but I haven't had the time nor the skill to make it work. 

    I, too, saw the GetUsage() method referenced in your link, but I did not have success with that. It appears to use the same ShareStats datatype that getstats uses, but it doesn't seem to work when called against the share object. Maybe it's deprecated? 

    Let me know if you figure out an easy way to call the data with REST. I was playing around with Curl and I was able to extract some information, but I have not yet made it work in any reproducible, automated way. 

    Thanks!

    Sspat

    Wednesday, September 18, 2019 2:16 PM
  • Hi Wei Wei,  do you know if this issue is only for “Microsoft.Azure.Storage.File” 11.0.1 , it is possible to downgrade the azure storage file module to avoid this issue?
    Thursday, October 3, 2019 4:45 PM