Collecting Disk Space from Network Share Drive

pdsqsql 411 Reputation points
2021-04-06T16:49:43.427+00:00

Hello,
We are having sometimes issue with the disk space where we are storing backup/Transaction log backup.
We have a frequent log backup job running which stores TLog files for different servers/databases on the network drive folder/server.
I would like to collect the data every day or few times a day to watch the growth of TLog files and overall disk usage so we can estimate the disk size and growth.
We are purging the files every day but still we are facing issue.
This is a Windows 2016 server.

Thanks for your help!

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,702 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 56,946 Reputation points
    2021-04-06T17:39:49.13+00:00

    Personally I think this should be the responsibility of your monitoring system that monitors your servers. If you're using a SAN then this should be part of their management tools. However if you are not setup for that scenario then getting the disk space and reporting errors is reasonable.

    The challenge with network shares is the data may not be 100% reliable in my experience, although things could have changed. A network share hosted on a file server may not report the actual size of the allocated drive, for security reasons or whatever nor may it actually show what is really remaining on the share. Quotas can complicate this as well because a quota limit might say you have 100MB left whereas the drive itself has plenty of space. But let's assume you're using a simple NAS that does report the size and policies aren't getting in the way.

    The easiest approach is to create a Powershell script that retrieves the data. You can then send an email or some other alert if the share goes below a certain level. If it were a logical drive then Get-PSDrive works. But mapped drives are per-user and relies on persistence which you probably don't want to deal with so instead you'll likely need to use UNC. However you can create a PS session temporary mapped drive to make it work using New-PSDrive.

       $drive = New-PSDrive -Name ShareCheck -PSProvider "FileSystem" -Root "\\server\share"  
    

    But it may or may not return the space correctly as mentioned earlier. There is one SO post that mentions that New-PSDrive doesn't return space information irrelevant but using the old net use command does work when used in combination with Get-PSDrive.

       net use 'X:' '\\server\share' /persistent:no  
       $drive = Get-PSDrive 'X'  
    

    Note: You should the mapping when done.

    WMI used to work but more recent PS versions don't seem to work quite as well. That would be an alternative if the NAS supports it.

    To get this to run set up a Scheduled Task in Windows to run as frequently as you want. Have it run your Powershell script whether anyone is logged in or not and you should be good to go. Note that you'll need to ensure the scheduled task is executed using an account that has appropriate access to the UNC path you are checking.


  2. JiayaoZhu 3,911 Reputation points
    2021-04-07T05:41:18.197+00:00

    Hi,

    Thank you for your posting!

    Based on your descriptions, I agree with @Michael Taylor . You can setup monitoring software on the servers that report to a central location, or you can create a Powershell script that retrieves the data. More information about create a PowerShell script can be seen in this blog as well, where you can further setup commands to monitor your free space in your network drive:

    https://social.technet.microsoft.com/Forums/ie/en-US/80d42412-e740-4146-9ad3-70ec6755d9c3/script-to-monitor-free-space-in-unc-path-network-drive?forum=winserverpowershell

    In addition, you can map the shared folder as a drive - this will show you how much free space is available on the shared folder. You can follow the steps to achieve this goal:

    1)In windows explorer, browse to the network share, then to the folder that you want to check the disk usage, right client on the folder and select properties.

    2)In the properties window, click on the "OES Info" tab, and check the "Space Available" field.

    More information about mapping the shared folder as a drive, along with the use of monitoring software can be seen in this article:

    https://www.uregina.ca/is/common/ur/technotes/615.html

    (Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.)

    Thank you for your support!

    Best regards
    Joann

    ------------------------------------------------------------------------------------------------------------------

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. JiayaoZhu 3,911 Reputation points
    2021-04-09T08:41:23.483+00:00

    Hi,

    Thank you for your reply!

    Based on your descriptions, I suppose you want to locally run PS scripts that can monitor network shared disk server which is remote from your SQL server. In addition, you need scripts that can restore the monitor report in your SQL server's table. In this case, after research, I think you can just run command Get-Volume from your SQL server. More information about command Get-Volume:

    https://learn.microsoft.com/en-us/powershell/module/storage/get-volume?view=windowsserver2019-ps
    Thank you for your understanding!

    Best regards
    Joan

    ------------------------------------------------------------------------------------------------------------------

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    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.