need script for space util

  • Hi,

    Can anyone share TSQL script for displaying each drive wise Total, Free , Free% space utilizaiton report so that if it is less than 30% I need to send out an email as output as Daily Monitor Activity. Looking for a script which can work on sql 2000 and above versions.

    Thanks in Advance.

  • The best way I have found to do this is using WMI but not from within T-SQL, from a PowerShell script. Use Get-WmiObject to read from class Win32_LogicalDisk against Windows 2000 Servers, and Win32_Volume (picks up mount points) against Windows 2003+ servers.

    edit: fix name of class Win32_Volume...typed Win32_LogicalVolume from memory

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • installing powershell do we any security risks as mine windows 2003. am not sure we can download sdk which has powershell 2.0.

    can u share the script?

  • Oracle_91 (3/24/2013)


    installing powershell do we any security risks as mine windows 2003. am not sure we can download sdk which has powershell 2.0.

    can u share the script?

    PowerShell is a safe option. Much safer than doing the same via T-SQL. You ought to read about it and become familiar. It is the platform Microsoft has chosen for all server-class software administration including SQL, Windows, IIS, Active Directory, Exchange, etc.

    I do not have scripts I can easily share. My admin scripts are tied into utility databases and other environment aspects. Here is an example for you to try against your 2003 server:

    $Computer = "ComputerName"

    Get-WMIObject Win32_Volume -Filter "DriveType=3" -Computer $Computer | Select SystemName,DeviceID,VolumeName,FileSystem,BlockSize,NumberOfBlocks,@{Name="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}},@{Name="freespace(%)";Expression={"{0:N1}" -f(($_.freespace/$_.size)*100)}})

    Just change the variable value to your computer name.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Hi,

    Thanks for the script. I installed powershell on one of my windows 7 machine. However, i am getting below error.Not sure, If I am using right command line. I replace the computer name with my PC name and tried executing and I dont see output. Please correct me if am doing something wrong as I am new to powershell.

    D:\>powershell.exe -noexit &'d:\b.ps1'

    Windows PowerShell

    Copyright (C) 2009 Microsoft Corporation. All rights reserved.

    PS D:\>

    PS D:\> exit

  • Read up on how to call a script using powershell.exe. That does nit look right. The ampersand is for code-blocks iirc. Just run the stuff I gave you at a PowerShell prompt to get comfortable before moving on to using saved scripts. Lookup Professor PowerShell, and look into book PowerShell 3.0 in 30 Days of Lunches.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Hi,

    Getting below error messgae when I execute it at powershell command.

    PS D:\>

    PS D:\> $Computer = "WIN7-PC"

    PS D:\> Get-WMIObject Win32_Volume -Filter "DriveType=3" -Computer $Computer | Select SystemName,DeviceID,VolumeName,FileSyst

    em,BlockSize,NumberOfBlocks,@{Name="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N

    1}" -f($_.freespace/1gb)}},@{Name="freespace(%)";Expression={"{0:N1}" -f(($_.freespace/$_.size)*100)}})

    Unexpected token ')' in expression or statement.

    At line:1 char:346

    + Get-WMIObject Win32_Volume -Filter "DriveType=3" -Computer $Computer | Select SystemName,DeviceID,VolumeName,FileSystem,Bl

    ockSize,NumberOfBlocks,@{Name="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}"

    -f($_.freespace/1gb)}},@{Name="freespace(%)";Expression={"{0:N1}" -f(($_.freespace/$_.size)*100)}}) <<<<

    + CategoryInfo : ParserError: ():String) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : UnexpectedToken

    PS D:\>

  • I may have picked up am extra trailing parent when it copied it from my script. Try removing that and see what you get. Better yet, deconstruct the command and understand what its doing, then tell me what's wrong with it 😉

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

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

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