VBS Script To Send Domain Controller Information To Excel

 

This VBS script will take a Domain Controller (DC) Name from an input box and write the following domain information to an excel spreadsheet.

 

DC Name, Domain Name, Client Site Name, Site Name, Description, DNS Forest Name, Directory Service, DNS Controller, DNS Domain, DNS Forest, Global Catalog, Kerberos Distribution Center, Primary Domain Controller and Time Service

 

VBS Script:

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

 

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

objExcel.Cells(2, 1).Value = "Domain Name"

objExcel.Cells(3, 1).Value = "Client Site Name"

objExcel.Cells(4, 1).Value = "Site Name"

objExcel.Cells(5, 1).Value = "Description"

objExcel.Cells(6, 1).Value = "DNS Forest Name"

objExcel.Cells(7, 1).Value = "Directory Service"

objExcel.Cells(8, 1).Value = "DNS Controller"

objExcel.Cells(9, 1).Value = "DNS Domain"

objExcel.Cells(10, 1).Value = "DNS Forest"

objExcel.Cells(11, 1).Value = "Global Catalog"

objExcel.Cells(12, 1).Value = "Kerberos Distribution Center"

objExcel.Cells(13, 1).Value = "Primary Domain Controller"

objExcel.Cells(14, 1).Value = "Time Service"

 

strComputer = InputBox("Enter Domain Controller Name")

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_NtDomain")

For Each objItem in colItems

objExcel.Cells(1, 2).Value = objItem.DomainControllerName

objExcel.Cells(2, 2).Value = objItem.DomainName

objExcel.Cells(3, 2).Value = objItem.ClientSiteName

objExcel.Cells(4, 2).Value = objItem.DcSiteName

objExcel.Cells(5, 2).Value = objItem.Description

objExcel.Cells(6, 2).Value = objItem.DnsForestName

 

If objItem.DSDirectoryServiceFlag = True Then

objExcel.Cells(7, 2).Value =  "Yes"

Else   

objExcel.Cells(7, 2).Value =  "No"

End If

 

If objItem.DSDnsControllerFlag = True Then

objExcel.Cells(8, 2).Value =  "Yes"

Else   

objExcel.Cells(8, 2).Value =  "No"

End If

 

If objItem.DSDnsDomainFlag = True Then

objExcel.Cells(9, 2).Value =  "Yes"

Else   

objExcel.Cells(9, 2).Value =  "No"

End If

 

If objItem.DSDnsForestFlag = True Then

objExcel.Cells(10, 2).Value =  "Yes"

Else   

objExcel.Cells(10, 2).Value =  "No"

End If

 

If objItem.DSGlobalCatalogFlag = True Then

objExcel.Cells(11, 2).Value =  "Yes"

Else   

objExcel.Cells(11, 2).Value =  "No"

End If

 

If objItem.DSKerberosDistributionCenterFlag = True Then

objExcel.Cells(12, 2).Value =  "Yes"

Else   

objExcel.Cells(12, 2).Value =  "No"

End If

 

If objItem.DSPrimaryDomainControllerFlag = True Then

objExcel.Cells(13, 2).Value =  "Yes"

Else   

objExcel.Cells(13, 2).Value =  "No"

End If

 

If objItem.DSTimeServiceFlag = True Then

objExcel.Cells(14, 2).Value =  "Yes"

Else   

objExcel.Cells(14, 2).Value =  "No"

End If

Next

 

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

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

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

objExcel.Cells.EntireColumn.AutoFit

 

 

 

Published Sunday, February 17, 2008 3:08 PM by dhite
Filed under:

Comments

No Comments