Free space on network drive

Tim Blundell 0 Reputation points
2023-06-27T21:18:06.72+00:00

In Powershell, Get-PSDrive and WMI queries (ex: Get-WmiObject Win32_MappedLogicalDisk) are showing innacurate values in terms of free space on a network share. The share has a user quota configured with File Service Ressource Management, on the server hosting the share.

Is there any other way to show free space on a mapped drive or file share via Powershell?

The Windows interface and dir command in DOS box are showing the correct value in terms of free space on the mapped drive in question.

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,776 Reputation points
    2023-06-28T14:10:10.58+00:00

    Hello Tim,

    Thank you for your question and for reaching out with your question today.

    If the Get-PSDrive and WMI queries are not showing accurate values for free space on a network share with user quotas configured, you can try using the Get-SmbShare cmdlet in PowerShell to retrieve the correct free space information. Here's an example:

    
    $sharePath = "\\server\share"  # Replace with the path to your network share
    
    $share = Get-SmbShare -Name $sharePath
    
    if ($share) {
    
        $freeSpace = $share.FreeSpace
    
        Write-Host "Free space on $sharePath: $freeSpace bytes"
    
    }
    
    else {
    
        Write-Host "Failed to retrieve information for $sharePath"
    
    }
    
    

    The Get-SmbShare cmdlet specifically retrieves information about SMB shares, including their free space. It should provide more accurate results compared to Get-PSDrive and WMI queries.

    Note that the Get-SmbShare cmdlet requires PowerShell version 3.0 or later and must be run with administrative privileges. Ensure that you have the necessary permissions to access the network share and retrieve the share information.

    If the issue persists or the Get-SmbShare cmdlet doesn't provide the expected results, it's possible that the user quota configuration with File Service Resource Management is causing discrepancies in the reported free space. In such cases, you may need to explore alternative methods, such as using .NET classes or APIs, to retrieve the free space information directly from the underlying file system.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote or accept as answer.


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.