Improved Drive Space Monitoring

  • Good morning Michael,

    I've been on Vacation.

    Your solution is very interesting! Never thought of using

    RunCmd """for /f ""tokens=* delims=s"" %f in ('dir /ad " & driveLetr & ":\') do @""sqlcmd.exe"" -S DBHostName -Q ""set nocount on; insert into dbatools.dbo.diskfreeimport values('%f');"""""

    Do you think this could be expanded to also return total space??

  • Pradeep, Does this help you?

    declare @cmd varchar(2000)

    declare @Name varchar(100)

    declare @reterror int

    Set @Name = 'Pradeep.vbs'

    set @cmd =

    'bcp "Select ''First Line Here'' Union All '

    + 'Select ''Second Line Here'' Union All '

    + 'Select ''ABC'' Union All '

    + 'Select ''123'''

    +' " queryout C:\' + @name +' -b5000 -c -t"" -T'

    print @cmd

    --Select len(@cmd)

    --execute @RETERROR = master..xp_cmdshell @cmd

    If @RETERROR <> 0

    Begin

    --You know the rest here

    Select getdate()

    End

    Don't forget to uncomment the Execute.

  • Grasshopper,

    Sorry for the delayed response, I have been busy with a "not" vacation (swamped at work). I tried a few methods and the only way I could determine total space in DOS was to use chkdsk c: /c /i, but this is a very slow and disk-intensive process just to get free space... diskpart would work if it did not require a temporary file for scripting input -- why couldn't they just make it accept the script on the command line, like ntdsutil or iisutil?

    Anyway, the answer is yes it can be done, but with a lot of slow, heavy drive activity. We're back to ActiveX scripting of WMI to efficiently get total space.

Viewing 3 posts - 16 through 17 (of 17 total)

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