April 30, 2009 at 11:01 pm
Comments posted to this topic are about the item Disk Space Report
May 18, 2009 at 5:12 am
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!
May 18, 2009 at 8:15 am
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
May 18, 2009 at 8:19 am
Your Script Looks much more formatted!
Thanks again for clicking my first article!
May 18, 2009 at 8:22 am
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
May 18, 2009 at 8:25 am
There is also a very good utility to know what properties can be pulled. Check out the WMI browser from MS.
May 27, 2010 at 6:00 am
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
May 19, 2016 at 7:04 am
Thanks for the script.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply