VBS Script To Send All AD Domain Controllers Disk Space Information To Excel

 

This VBS script will write all the Active Directory (AD) Domain Controllers local disk space information to excel for the local AD domain.

 

VBS Script:

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Server Name"

objExcel.Cells(1, 2).Value = "Drive Letter"

objExcel.Cells(1, 3).Value = "Total Space (GB)"

objExcel.Cells(1, 4).Value = "Free Space (GB)"

 

Set objDomain = GetObject("LDAP://RootDSE")

strDomain = objDomain.Get("DefaultNamingContext")

Set objOU = GetObject("LDAP://ou=Domain Controllers," & strDomain)

For Each strServer In objOU

 

Set objWMIService = GetObject("winmgmts:\\" & strServer.CN & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")

For Each objItem in colItems

 

objExcel.Cells(intRow, 1).Value = strServer.Cn

objExcel.Cells(intRow, 2).Value = objItem.Name

objExcel.Cells(intRow, 3).Value = (FormatNumber(objItem.Size/ 1024^3, 1)) & " GB"

objExcel.Cells(intRow, 4).Value = (FormatNumber(objItem.Freespace/ 1024^3, 1)) & " GB"

intRow = intRow + 1

Next

Next

 

objExcel.Range("A1:D1").Select

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Range("A1:D1").Select

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

 

 

Published Sunday, March 16, 2008 8:42 AM by dhite
Filed under:

Comments

No Comments