Obtaining total capacity for disk drive in T-SQL

  • I have some scripts to gather stats from several servers and it would be useful to be able to get total disk capacity. vbscript is not an option so it needs to be t-sql/ xp_cmdshell. Any undocumented SPs that might give this information?

  • You can use sp_OACreate and invoke the System.FileSystemObject.

    From that you could get the avaliable size.

    Not sure if there is a better way.

    Cheers,

    Crispin

    Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!

  • Exec Master..xp_fixeddrives will give you free space avail. in MB

    MW


    MW

  • Try

    execute master..xp_cmdshell 'srvinfo -ns'

    which gives you disk capacity, used and free

    (Thanks to Bill from Walmart for this)

  • srvinfo gets a bunch of stuff, but takes some parsing.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

  • Thanks everyone for the replies - srvinfo looks like the one for me!

  • "srvinfo" never worked for me. Am I missing something?

    paul


    paul

  • What SQL Server version/pack needs to be installed to use srvinfo, or could you point me to some documentation on it. I checked BOL and didn't find anything. The reason why I ask is that I have some servers that xp_cmdshell 'srvinfo -ns' works for while others don't and SQL Server Version as well as pack is different on all of the machines.

    Work like you don't need the money.

    Love like you've never been hurt.

    And Dance like no one is watching.


    Work like you don't need the money.
    Love like you've never been hurt.
    And Dance like no one is watching.

  • srvinfo comes with an Operating system's resource kit. I found it in NT 4.0's copy but found references in more recent kits. Unfortunately it isn't one of the tools available free through Microsoft's web site.

    There is a way to get a comma delimited file of the drive, drive size, used space, free space for each drive on the server. But your SQL service account will need access those drives.

    Hope this helps,

    Michelle



    Michelle

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply