HELP Needed urgently to modify a script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
pkchambel
Posts: 1
Last visit: Wed Sep 05, 2007 1:58 pm

HELP Needed urgently to modify a script

Post by pkchambel »

Hi everyone I am in desperate need of help. I found the following script here titled DC_Info (see below) that does exactly what I want as I have various domains and need all the information requested in this script from all the domains.

However the only thing I would like to change is to give me information about all the servers in my domains and not just the DCs. All my servers contain *SRV* on the name. if it is not possible it could return all the computers and I could filter the spreadsheet. Please help ASAP

Thank you everyone and to the person that first put up this script

________________________
'<-- BEGIN Excel Check -->' Ensure Excel is installed locallyOn Error Resume NextSet objExcel = CreateObject("Excel.Application")If Err.Number <> 0 Then On Error GoTo 0 WScript.Echo "Excel application not found." WScript.QuitEnd IfOn Error GoTo 0'<-- END Excel Check -->
'<-- BEGIN Domain Enumeration -->' Enumerate all domains in the current forestOn Error Resume NextSet objShell = WScript.CreateObject("Wscript.Shell")Set objRootDSE = GetObject("LDAP://RootDSE")strADsPath = "<GC://" & objRootDSE.Get("rootDomainNamingContext") & ">;"strFilter = "(objectcategory=domainDNS);"strAttrs = "distinguishedname;"strScope = "SubTree"Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")objName = objFSO.GetTempNameobjTempFile = objNameSet outfile = objFSO.OpenTextFile(objTempFile, 2, True)Set objConn = CreateObject("ADODB.Connection")objConn.Provider = "ADsDSOObject"objConn.Open "Active Directory Provider"Set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope)objRS.MoveFirstWhile Not objRS.EOF outfile.writeline objRS.Fields(0).Value objRS.MoveNextWendoutfile.close' Read domains into an ArraySet infile = objFSO.OpenTextFile(objTempFile)str = infile.ReadAll()SvrArray = Split(str, VbCrLf)s=1objTextFile.CloseobjFSO.DeleteFile(objTempFile)'<-- END Domain Enumeration -->
'<-- BEGIN Main Script Processes -->For Each strDom In SvrArray' Regular expressions to format domain names Set regex = CreateObject("VBScript.RegExp") regex.Pattern = "DC=" regex.Global = True regex.IgnoreCase = True ReplacedString = regex.Replace(strDom, "") regex.Pattern = "," ReplacedString = regex.Replace(ReplacedString, ".") regex.Pattern = "DC=" strExcelPath = "c:ScriptsDC_Info.xls" strDomain = ReplacedString ' Create Excel workbook If s = 1 Then objExcel.Workbooks.Add objExcel.ActiveWorkbook.Worksheets.Add objExcel.ActiveWorkbook.Worksheets.Add End If Set objSheet = objExcel.ActiveWorkbook.Worksheets(s) objSheet.Name = UCase(strDomain) objSheet.Range("A1:F25").Font.Size = 8 objSheet.Range("A1:F1").Font.Bold = True objSheet.Range("B2:B25").HorizontalAlignment = -4108 objSheet.Range("F2:F25").HorizontalAlignment = -4108 ObjSheet.Columns(1).Columnwidth = 24 ObjSheet.Columns(2).Columnwidth = 12 ObjSheet.Columns(3).Columnwidth = 16 ObjSheet.Columns(4).Columnwidth = 11 ObjSheet.Columns(5).Columnwidth = 30 ObjSheet.Columns(6).Columnwidth = 11 i = 1 intRow = 2 intCola = 2 intColb = 3 intColc = 4 intCold = 5 intCole = 6 objSheet.Cells(1, 1).Value = "DC Name" objSheet.Cells(1, 2).Value = "Global Catalog" objSheet.Cells(1, 3).Value = "Site Name" objSheet.Cells(1, 4).Value = "IP Address" objSheet.Cells(1, 5).Value = "OS Version" objSheet.Cells(1, 6).Value = "Service Pack"
'Domain Controller Name Set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE") set objDomain = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext")) strMasteredBy = objDomain.GetEx("masteredBy")
For Each strNTDSDN In strMasteredBy Set objNTDS = GetObject("LDAP://" & strNTDSDN) regex.Pattern = "gs,CN=(w+),CN=Se" 'Obtain server RDN Set objMatches = regex.Execute(strNTDSDN) Set objServer = GetObject(objNTDS.Parent) objSheet.Cells(intRow, 1).Value =objServer.Get("dnsHostName") For Each objMatch In objMatches '<-- BEGIN GC Check --> ' Determine if server is a GC strLen = Len(objMatch.Value)-12 strRight = Mid(ObjMatch.Value, 7, strLen) Set objRoot = GetObject("LDAP://" & strRight & "/RootDSE") objDSServiceDN = objRoot.Get("dsServiceName") Set objDSRoot = GetObject("LDAP://" & strRight & "/" & objDSServiceDN ) blnCurrentOptions = objDSRoot.Get("options") If blnCurrentOptions Then objSheet.Cells(intRow, intCola).Value = "YES" Else objSheet.Cells(intRow, intCola).Value = "NO" End If '<-- END GC Check --> '<-- BEGIN SITE NAME --> ' Enumerate site name of DC Set objNTDSsite = GetObject("LDAP://" & objRoot.Get("dsServiceName")) Set objSite = GetObject(GetObject(GetObject(objNTDS.Parent).Parent).Parent) objSheet.Cells(intRow, intColb).Value = objSite.Get("cn") '<-- END SITE NAME --> '<-- BEGIN IP ADDRESS --> ' Obtain remote IP address Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject") Set objShell = Wscript.CreateObject("Wscript.Shell") objName = objFSO.GetTempName objTempFile = objName objShell.Run "cmd /c ping -n 3 -w 1000 " & strRight & " >" & objTempFile, 0, True Set objTextFile = objFSO.OpenTextFile(objTempFile) regex.Pattern = "bd{1,3}.d{1,3}.d{1,3}.d{1,3}b" 'RegEx for remote IP address strContents = objTextFile.ReadAll() PingArray = Split(strContents, vbCrLf) For Each strPing In PingArray Set objMatchesA = regex.Execute(strPing) For Each objMatchA In ObjMatchesA If i = 1 Then objSheet.Cells(intRow, intColc).Value = objMatchA.Value End If i = i+1 Next Next i=1 Next '<-- END IP ADDRESS --> objTextFile.Close objFSO.DeleteFile(objTempFile) '<-- BEGIN OS and Service Pack --> ' Enumerate current OS Version and Service Packs Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strRight & "rootcimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems objSheet.Cells(intRow, intCold).Value = objOperatingSystem.Caption & " " & _ objOperatingSystem.Version Next For Each objOperatingSystem in colOperatingSystems objSheet.Cells(intRow, intCole).Value = objOperatingSystem.ServicePackMajorVersion _ & "." & objOperatingSystem.ServicePackMinorVersion Next '<-- END OS and Service Pack --> intRow = intRow+1 Next Set regex = Nothing s=s+1NextMsgBox "Script Completed"'<-- Clean up -->objExcel.ActiveWorkbook.SaveAs strExcelPathobjExcel.ActiveWorkbook.CloseobjExcel.Application.QuitobjTextFile.CloseobjFSO.DeleteFile(objTempFile)WScript.Quit
______________________________
This topic is 16 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked