SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


need script for space util


need script for space util

Author
Message
Oracle_91
Oracle_91
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3172 Visits: 1742
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.
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38688 Visits: 14411
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
Oracle_91
Oracle_91
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3172 Visits: 1742
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?
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38688 Visits: 14411
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
Oracle_91
Oracle_91
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3172 Visits: 1742
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
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38688 Visits: 14411
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
Oracle_91
Oracle_91
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3172 Visits: 1742
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:\>
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38688 Visits: 14411
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search