• mani@123 (1/22/2013)


    SERVER2008:

    declare @svrName varchar(255)

    declare @sql varchar(400)

    --by default it will take the current server name, we can the set the server name as well

    set @svrName = @@SERVERNAME

    [font="Arial Black"]set @sql = 'powershell.exe [/font]-c "Get-WmiObject -Class Win32_Volume -Filter ''DriveType = 3'' | select name,capacity,freespace | foreach{$_.name+''|''+$_.capacity/1048576+''%''+$_.freespace/1048576+''*''}"'

    --creating a temporary table

    CREATE TABLE #output

    (line varchar(255))

    --inserting disk name, total space and free space value in to temporary table

    insert #output

    [font="Arial Black"]EXEC xp_cmdshell @sql[/font]

    +10000000000000000000000 Mani!!! I absolutely freakin' love it! 🙂 I was starting to think I was the only one in the world that did that!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)