Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

System Admins

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Developer, can do new tricks, require good homeGetting remote SQL Service information with Windows Powershell »
    comments

    In a previous post I showed how to get remote disk information with PowerShell. The script works nice until you execute it on a server with Mount Points. When executing the following script on a server with Mount Points:

    1. Get-WmiObject win32_logicaldisk -computer <computername> |
    2. select-object DeviceID, VolumeName, @{Name="Size";Expression={$_.Size/1GB}},@{Name="FreeSpace";Expression={$_.FreeSpace/1GB}},
    3. @{Name="PCTFreeSpace";Expression={
    4. $_.FreeSpace/$_.Size*100}}|Sort-Object -descending PCTfreespace|format-table

    I get the following result:

    Knowing the sizes of my databases, I knew the numbers were wrong. So I opened a RDP session to the server and found this picture in Disk Management:

    At that moment I realized I wasn't getting the information from the Mount Points, just from the Disks that had a drive letter assigned to them.
    So let's find out how we can get that information with Windows PowerShell. I still need the wmiobject but instead of the win32_logicaldisk I'm going to use the win32_volume. I also replace the DeviceID and VolumeName objects with Name and Label:

    1. get-wmiobject win32_volume -computer <computername\|
    2. select name, label, driveletter

    The result looks like this:

    As you can see, the drive letter properties are empty for my Mount Points and in the name column I can find the file and folder where they are mounted.
    So let's find the space, free space and percentage free space of the volumes. I can use the calculations from my previous script only Size needs to be replaced with Capacity:

    1. get-wmiobject win32_volume -computer <computername\|
    2. select name, label, @{Name="Capacity (GB)";Expression={$_.Capacity/1GB}},@{Name="FreeSpace (GB)";Expression={$_.FreeSpace/1GB}},
    3. @{Name="FreeSpace (PCT)";Expression={$_.FreeSpace/$_.Capacity*100}} |
    4. format-table

    The result now shows the drives and Mount Points with all the requested information:

    To be able to reuse the script I do what I did in the other two PowerShell post:

    1. param(
    2.     [string] $compname = $(Throw "Provide a Server name as first parameter")
    3. )
    4. Get-WmiObject win32_volume -computer $compname |
    5. select name, label, @{Name="Capacity (GB)";Expression={$_.Capacity/1GB}},
    6. @{Name="FreeSpace (GB)";Expression={$_.FreeSpace/1GB}},
    7. @{Name="FreeSpace (PCT)";Expression={$_.FreeSpace/$_.Capacity*100}} |
    8. format-table

    End that's it, the next request for free disk space is a matter of seconds again.

    About the Author

    User bio imageAxel started his IT career more than a decade ago. After a few months he was the accidental DBA for the SQL Server 6.5 running the Service Desk application. It didn't took long or Axel started to focus on SQL Server and after another year he became the full-time DBA in a large Belgian datacenter managing the SQL Servers for the hosted customers.It's more than five years now since he switched to consulting and teaching SQL Server. Axel is a Microsoft Certified DBA and Trainer.
    Social SitingsTwitterLinkedInLTD RSS Feed
    3345 views
    InstapaperVote on HN

    No feedback yet

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)