getSQLinfo.vbs 'script to get SQL DATA/LOG Space Used, Space unused, and Space Free 'Author: Felipe Ferreira, Daniel Magrini 'Date: 05/07/07 'Version 2,0
'@@TO CHANGE::: SERVERNAME\Instance, domain\user, password AND DATABSE!
'____________________________________________________________________________ Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set oFSO = CreateObject("Scripting.FilesyStemObject") outputfile = "CheckSqlDB_Size.txt" Set ofile = oFso.OpenTextFile(outputfile,8, True) oFile.Writeline "######################################################" oFile.Writeline "This command executed in " Date " at " Time VbCrLf '____________________________________________________________________________
CheckSQLData CheckSQLLOG
'############## GET SQL DATA SPACE USED, SPACE TOTAL, SPACE FREE 'Function checkSQL(strServer,strDB) in the future make it a function.... Sub CheckSQLDATA Const adOpenDynamic = 1, adLockOptimistic = 3 Dim strQuery Dim objConnection, objRecordSet Dim strQueryResult, strQueryResult2 Dim UsedDataSpace, TotalDataSpace, FreeDataSpace Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset")
'Write on File ofile.WriteLine "Used DATA Space(MB) = " UsedDataSpace ofile.WriteLine "Free DATA Space(MB) = " FreeDataSpace ofile.WriteLine "Total DATA Space(MB) = " TotalDataSpace
objRecordSet.MoveNext loop end if objRecordSet.Close objConnection.Close set objConnection = nothing set objRecordSet = nothing end sub
Sub CheckSQLLOG Const adOpenDynamic = 1, adLockOptimistic = 3 Dim strQuery Dim objConnection, objRecordSet Dim strQueryResult, strQueryResult2 Dim UsedLogSpace, TotalLogSpace, FreeLogSpace Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset")