Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Disk Space Report Expand / Collapse
Author
Message
Posted Thursday, April 30, 2009 11:01 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, September 8, 2014 10:15 AM
Points: 732, Visits: 408
Comments posted to this topic are about the item Disk Space Report
Post #708253
Posted Monday, May 18, 2009 5:12 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 22, 2014 12:26 PM
Points: 318, Visits: 163
Thanks for posting this, I used to have something very similar that has one more for loop to read servers from a text file. Here is my stab at it the powershell way:
#drspacev2.ps1
#Iterate a list of servers (src:a text file in d:\ps_scripts\servers.txt) through the WMI interface in windows.
#Collect a list of stats on all local drives for each server and store data
#in a csv file pipe"|" delimited at c:\temp\freespace.csv
New-Item c:\temp\Freespace.csv -type file -force | out-null;
$srvr = Get-Content C:\Temp\Servers.txt; foreach($row in $srvr) {
Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer $row| Select SystemName,DeviceID,VolumeName,size,freespace | foreach{$_.DeviceID}{$row+"|"+$_.DeviceID+"|"+$_.size/1mb+"|"+$_.freespace/1mb+"|FileSpace"|add-content c:\temp\Freespace.csv}}


This will iterate a text file named "Servers.txt" and grab all the freespace for "FIXED" drives, for each server in the text file. I even took this another step further creating a FormatFile, importing the data, and creating a conditionalized "Freespace" report in SSRS. (Conditionalized meaning the cells are colored red, lt. yellow, and blue depending on the amount of free space.) If anyone is interested I can write this up. Thanks again for your script aditya!
Post #718946
Posted Monday, May 18, 2009 8:15 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 16, 2014 9:38 AM
Points: 22, Visits: 148
Can the .vbs script query/display the drive letter instead of the drive name? Currently it's only displaying the drive name (optional in windows) which for most of our drives is null. thnx.

lc
Post #719099
Posted Monday, May 18, 2009 8:19 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, September 8, 2014 10:15 AM
Points: 732, Visits: 408
Your Script Looks much more formatted!

Thanks again for clicking my first article!
Post #719106
Posted Monday, May 18, 2009 8:22 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, September 8, 2014 10:15 AM
Points: 732, Visits: 408
It can display the drive letter...

Chk this out for the Win32_Volume WMI Event

http://www.it-visions.de/Scripting/WMIReferenz.asp?C_Klasse=Win32_Volume
Post #719113
Posted Monday, May 18, 2009 8:25 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 22, 2014 12:26 PM
Points: 318, Visits: 163
There is also a very good utility to know what properties can be pulled. Check out the WMI browser from MS.
http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en
Post #719117
Posted Thursday, May 27, 2010 6:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 14, 2014 1:17 PM
Points: 5, Visits: 158
I have a similar vbscript to the one RJ provided that pulls a list of servers from a tbl I maintain on our sql boxes to track os and sql updates, ram, etc. The script loops through each server and returns the space infromation and loads it to a second tbl in the db with the server id so the space tbl can be joined to the server tbl. The script worked really well but my DBA has since become a powershell fanatic and replaced it.

Option Explicit

Dim oServerList, oSpaceTable, strServer, strServerID,strFreeSpace,strusedSpace, strDiskSize, strHDD, strTextFilePath, txt
Dim objWMIService, objItem, colItems,objFSO,objTextFile

'open our connections
set oServerList=createobject("adodb.recordset")
oServerList.open "SELECT * FROM [tblServer] WHERE localmonitor = 0" , "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Administration;Data Source=SQLDISTRIB;Application Name=DiskSpace Monitor"

set oSpaceTable=createobject("adodb.connection")
oSpaceTable.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Administration;Data Source=SQLDISTRIB;Application Name=DiskSpace Monitor"

' set the path for the error log file
strTextFilePath = "D:\CommonTools\Scripts\Log\errorlog.txt"
txt = "ServerID" & vbtab & "Server" & vbtab & "Error Description" & vbcrlf

' loop through or sql server tbl to get the server names we will need to go after.
Do While Not oServerList.EOF
'WScript.Echo oServerList("server").Value
strServer = oServerList("Server")
strServerID = oServerList("ServerID")
'msgbox strserver & " " & strServerID

' turn on our error handling
On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\cimv2")

If Err.Number <> 0 Then
txt = txt & strServerID & vbtab & strServer & vbtab & Err.Description & vbcrlf

oServerList.MoveNext

Else

Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
For Each objItem in colItems

'pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
strDiskSize = Int(objItem.Size)
strFreeSpace = Int(objItem.FreeSpace)
strUsedSpace = Int(objItem.Size-objItem.FreeSpace)
strHDD = Replace(objItem.Name,":","")


oSpaceTable.execute "INSERT INTO tblServerSpace ([serverid],[hdd],[totalsize],[freespace],[usedspace]) VALUES ('"& strServerID & "','" & strHDD & "','" & strDiskSize & "','" & strFreeSpace & "','" & strusedSpace & "')"
Next

End If

oServerList.MoveNext

Loop


Set oServerList = Nothing


' write the error log to teh file.
SET objFSO = createobject("Scripting.FileSystemObject")
SET objTextFile = objFSO.CreateTextFile(strTextFilePath)
objTextFile.Write(txt)
objTextFile.Close
SET objTextFile = nothing

wscript.echo txt
wscript.quit
Post #928913
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse