TSQL for getting detailed drive info on a Cluster

  • Hi guys,

    I have a problem that I've been struggling and thought someone might help.

    I am running the script below to get detailed drive information on most of our servers. However, when I run it on a Cluster, the script doesn't show the right values for the 'Volume Label' for the shared storage drives. Any ideas would be greatly appreciated:

    Code used:

    SET NOCOUNT ON

    IF EXISTS (SELECT name FROM tempdb..sysobjects WHERE name = '##_DriveSpace')

    DROP TABLE ##_DriveSpace

    IF EXISTS (SELECT name FROM tempdb..sysobjects WHERE name = '##_DriveInfo')

    DROP TABLE ##_DriveInfo

    DECLARE @Result INT

    , @objFSO INT

    , @Drv INT

    , @cDrive VARCHAR(13)

    , @Size VARCHAR(50)

    , @Free VARCHAR(50)

    , @Label varchar(10)

    CREATE TABLE ##_DriveSpace

    (

    DriveLetter CHAR(1) not null

    , FreeSpace VARCHAR(10) not null

    )

    CREATE TABLE ##_DriveInfo

    (

    DriveLetter CHAR(1)

    , TotalSpace bigint

    , FreeSpace bigint

    , Label varchar(10)

    )

    INSERT INTO ##_DriveSpace

    EXEC master.dbo.xp_fixeddrives

    -- Iterate through drive letters.

    DECLARE curDriveLetters CURSOR

    FOR SELECT driveletter FROM ##_DriveSpace

    DECLARE @DriveLetter char(1)

    OPEN curDriveLetters

    FETCH NEXT FROM curDriveLetters INTO @DriveLetter

    WHILE (@@fetch_status <> -1)

    BEGIN

    IF (@@fetch_status <> -2)

    BEGIN

    SET @cDrive = 'GetDrive("' + @DriveLetter + '")'

    EXEC @Result = sp_OACreate 'Scripting.FileSystemObject', @objFSO OUTPUT

    IF @Result = 0

    EXEC @Result = sp_OAMethod @objFSO, @cDrive, @Drv OUTPUT

    IF @Result = 0

    EXEC @Result = sp_OAGetProperty @Drv,'TotalSize', @Size OUTPUT

    IF @Result = 0

    EXEC @Result = sp_OAGetProperty @Drv,'FreeSpace', @Free OUTPUT

    IF @Result = 0

    EXEC @Result = sp_OAGetProperty @Drv,'VolumeName', @Label OUTPUT

    IF @Result <> 0

    EXEC sp_OADestroy @Drv

    EXEC sp_OADestroy @objFSO

    SET @Size = (CONVERT(BIGINT,@Size) / 1048576 )

    SET @Free = (CONVERT(BIGINT,@Free) / 1048576 )

    INSERT INTO ##_DriveInfo

    VALUES (@DriveLetter, @Size, @Free, @Label)

    END

    FETCH NEXT FROM curDriveLetters INTO @DriveLetter

    END

    CLOSE curDriveLetters

    DEALLOCATE curDriveLetters

    -- Produce report.

    SELECT DriveLetter

    , Label

    , FreeSpace/1024 AS [FreeSpace GB]

    , TotalSpace/1024 AS [TotalSpace GB]

    FROM ##_DriveInfo

    ORDER BY [DriveLetter] ASC

    DROP TABLE ##_DriveSpace

    DROP TABLE ##_DriveInfo

    SET NOCOUNT OFF

  • I'm already working on a similar case, but I won't post my result until it's finished. Unfortunately, you cannot find information about mounted volumes using T-SQL only.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • for mounted volumes use the following

    wmic volume get name, "Free Space", capacity

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Oh, I know. Btw, can you imagine that .net I unaware of mounted volumes? I find thata bit surprising. WMI is great 🙂



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

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