Search

VB Scripts to get Complete information of Windows OS system into Excel sheet

Exported from Notepad++
Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Set objFSO = CreateObject("Scripting.FileSystemObject") strComputer="localhost" on error resume next LoginDateRange=30 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") If Err.Number <> 0 Then Err.Clear else Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems if objItem.CSName ="" then else strComputer= objItem.CSName end if Next End If Set objTextFile = objFSO.CreateTextFile("." & strComputer & ".csv", True) objTextFile.WriteLine strComputer & ",NETWORK,1,RESPONDS TO PING,YES" if instr(1,strcomputer,"ADC") = 0 then StartDate=DateAdd("d",-LoginDateRange,now()) alreadydone=1 Set objWMI = GetObject("winmgmts:\\" & StrComputer & "\root\cimv2") Set colLoggedEvents = objWMI.ExecQuery ("select * from Win32_NTLogEvent Where Logfile ='Security' AND TimeWritten > '" & StartDate &"'") 'AND EventCode IN ('528','551','4647','4634')") For Each objItem in colLoggedEvents if alreadydone < 11 then if objItem.EventCode = "528" or objItem.EventCode = "551" or objItem.EventCode = "4647" or objItem.EventCode = "4634" then objTextFile.WriteLine strComputer & ",Login," & alreadydone & ",LastLoginTime," & WMIDateStringToDate(objItem.TimeGenerated) objTextFile.WriteLine strComputer & ",Login," & alreadydone & ",LastLoggedInUser," & objItem.User alreadydone=alreadydone+1 end if end if Next if alreadydone=1 then objTextFile.WriteLine strComputer & ",Login,1,LastLoginTime,no Logins in the last " & LoginDateRange &" days " end if else objTextFile.WriteLine strComputer & ",Login,1,Domain Controller no Login audit completed" end if Root = "\\" & strComputer CTemp = returnSize & Foldersize(Root & "\C$\Temp") CUSers = returnSize & Foldersize(Root & "\C$\Users") DTemp = returnSize & Foldersize(Root & "\D$\Temp") CRecycler = returnSize & Foldersize(Root & "\C$\Recycler") DRecycler = returnSize & Foldersize(Root & "\D$\Recycler") Docs = returnSize & Foldersize(Root & "\C$\Documents and Settings") CLogFiles = returnSize & Foldersize(Root & "\C$\Windows\System32\LogFiles") DLogFiles = returnSize & Foldersize(Root & "\D$\LogFiles") Shiva = returnSize & Foldersize(Root & "\D$\Shiva") web = returnSize & Foldersize(Root & "\D$\Web") ErrorRep = returnSize & Foldersize(Root & "\C$\Windows\PCHealth\ErrorRep") Ci386 = returnSize & Foldersize(Root & "\C$\i386") di386 = returnSize & Foldersize(Root & "\D$\i386") objTextFile.WriteLine strComputer & ",folder,1,C TEMP," & CTemp objTextFile.WriteLine strComputer & ",folder,1,C Users," & CUSers objTextFile.WriteLine strComputer & ",folder,1,D TEMP," & DTemp objTextFile.WriteLine strComputer & ",folder,1,C Recyle Bin," & CRecycler objTextFile.WriteLine strComputer & ",folder,1,D Recycle Bin," & DRecycler objTextFile.WriteLine strComputer & ",folder,1,Documents and settings," & Docs objTextFile.WriteLine strComputer & ",folder,1,C Logs," & CLogFiles objTextFile.WriteLine strComputer & ",folder,1,D Logs," & DLogFiles objTextFile.WriteLine strComputer & ",folder,1, Shiva ," & Shiva objTextFile.WriteLine strComputer & ",folder,1,Web ," & web objTextFile.WriteLine strComputer & ",folder,1,Error reporting ," & ErrorRep objTextFile.WriteLine strComputer & ",folder,1,ci386 ," & ci386 objTextFile.WriteLine strComputer & ",folder,1,di366 ," & di386 i=1 Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2") Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume") For Each objVolume in colVolumes objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Drive," & objVolume.DriveLetter errResult = objVolume.DefragAnalysis(blnRecommended, objReport) If errResult = 0 then objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Disk Cluster Size," & objReport.ClusterSize objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",% Fragmentation," & objReport.FilePercentFragmentation objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",MFT % IN USE," & objReport.MFTPercentInUse objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",MFT Records," & bjReport.MFTRecordCount objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Excess Fragments," & objReport.TotalExcessFragments objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Total Files," & objReport.TotalFiles objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Total Folders," & objReport.TotalFolders objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Total Fragmented Files," & objReport.TotalFragmentedFiles objTextFile.WriteLine strComputer & ",DEFRAG," & i & ",Total MTF Fragments," & objReport.TotalMFTFragments End If i = i + 1 Next i=1 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTEventlogFile", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems objTextFile.WriteLine strComputer & ",EVENT," & i & ",Log name ," & objItem.LogfileName objTextFile.WriteLine strComputer & ",EVENT," & i & ",Log Size ," & objItem.FileSize/1024/1024 objTextFile.WriteLine strComputer & ",EVENT," & i & ",Log Max Size ," & objItem.MaxFileSize/1024/1024 objTextFile.WriteLine strComputer & ",EVENT," & i & ",Log OverWritePolicy ," & objItem.OverWritePolicy i= i +1 Next i=1 Const HKEY_USERS = &H80000003 strKeyPath = "S-1-5-18\Control Panel\International" strEntryName1 = "sCountry" strEntryName2 = "sShortDate" Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") objReg.EnumKey HKEY_Users, strKeyPath, arrSubKeys For Each subkey In arrSubKeys set strKeyPath = "HKEY_USERS\" & strKeyPath '& subkey & "\" objReg.GetStringValue HKEY_USERS, strKeyPath, strEntryName1, strValue1 objReg.GetStringValue HKEY_USERS, strKeyPath, strEntryName2, strValue2 objTextFile.WriteLine strComputer & ",CONFIG," & i & ",Locale Acc 18 ," & strValue1 & "-" & strValue2 Next strKeyPath1 = "S-1-5-19\Control Panel\International" strEntryName3 = "sCountry" strEntryName4 = "sShortDate" Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") objReg.EnumKey HKEY_Users, strKeyPath, arrSubKeys For Each subkey In arrSubKeys set strKeyPath = "HKEY_USERS\" & strKeyPath1 '& subkey & "\" objReg.GetStringValue HKEY_USERS, strKeyPath1, strEntryName3, strValue1 objReg.GetStringValue HKEY_USERS, strKeyPath1, strEntryName4, strValue2 objTextFile.WriteLine strComputer & ",CONFIG," & i & ",Locale Acc 19 ," & strValue1 & "-" & strValue2 Next strKeyPath2 = "S-1-5-20\Control Panel\International" strEntryName5 = "sCountry" strEntryName6 = "sShortDate" Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") objReg.EnumKey HKEY_Users, strKeyPath2, arrSubKeys For Each subkey In arrSubKeys set strKeyPath = "HKEY_USERS\" & strKeyPath2 '& subkey & "\" objReg.GetStringValue HKEY_USERS, strKeyPath2, strEntryName5, strValue1 objReg.GetStringValue HKEY_USERS, strKeyPath2, strEntryName6, strValue2 objTextFile.WriteLine strComputer & ",CONFIG," & i & ",Locale Acc 20 ," & strValue1 & "-" & strValue2 Next i=1 Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" strEntry1a = "DisplayName" strEntry1b = "QuietDisplayName" strEntry2 = "InstallDate" strEntry3 = "VersionMajor" strEntry4 = "VersionMinor" strEntry5 = "EstimatedSize" Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv") objReg.EnumKey HKLM, strKey, arrSubkeys For Each strSubkey In arrSubkeys intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1a, strValue1) If intRet1 <> 0 Then objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1b, strValue1 End If If strValue1 <> "" Then DisplayName = strValue1 else DisplayName="" End If objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2 If strValue2 <> "" Then InstallDate =strValue2 InstallYear= Left(InstallDate,4) InstallMonthYear=Right(Installdate,4) InstallMonth=Left(InstallMonthYear,2) InstallDay=Right(InstallMonthYear,2) InstallDate= InstallDay & "/" & InstallMonth & "/" & InstallYear else InstallDate="" End If objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry3, intValue3 objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry4, intValue4 If intValue3 <> "" Then Version = intValue3 & "." & intValue4 else version="" End If objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry5, intValue5 If intValue5 <> "" Then InstallSize = Round(intValue5/1024, 3) & " megabytes" else Installsize="" End If if DisplayName <>"" then if instr(DisplayName,"Security") >0 then objTextFile.WriteLine strComputer & ",Patch," & i & ",Description," & DisplayName objTextFile.WriteLine strComputer & ",Patch," & i & ",Patch ID," & Version else objTextFile.WriteLine strComputer & ",Software," & i &",Install Date," & InstallDate objTextFile.WriteLine strComputer & ",Software," & i &",Display name ," & DisplayName objTextFile.WriteLine strComputer & ",Software," & i &",Version, " & Version objTextFile.WriteLine strComputer & ",Software," & i &",Installsize," & InstallSize End if end if i = i +1 Next i=1 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering") For Each objSoftware in colSoftware writeLine="True" if objSoftware.Description ="" then WriteLine="False" end if if inStr(objSoftware.Description, "File") >0 then WriteLine="False" end if if writeLine="True" then objTextFile.WriteLine strComputer & ",Patch," & i & ",Description," & objSoftware.Description objTextFile.WriteLine strComputer & ",Patch," & i & ",Patch ID," & objSoftware.hotfixid i=i+1 End if Next i=1 Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") For Each objItem in colItems DiskSize=round((((objItem.Size * 1)/1024)/1024/1024),2) 'DiskSize=objItem.Size DiskFree=round((((objItem.FreeSpace * 1)/1024)/1024/1024),2) 'DiskFree=objItem.FreeSpace Percentfree= Round((DiskFree/DiskSize)*100,0) objTextFile.WriteLine strComputer & ",DISK," & i & ",ID," & objItem.DeviceID objTextFile.WriteLine strComputer & ",DISK," & i & ",Size," & DiskSize objTextFile.WriteLine strComputer & ",DISK," & i & ",Volume," & objItem.VolumeName objTextFile.WriteLine strComputer & ",DISK," & i & ",Disk Free Space, " & DiskFree objTextFile.WriteLine strComputer & ",DISK," & i & ",% Free Space, " & Percentfree i =i+1 Next i=1 Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objItem in colItems if objItem.Item="0809" then LocalSetting="UK" else LocalSetting="NON UK" End if objTextFile.WriteLine strComputer & ",OS," & i & ",Operating System," & objItem.Name objTextFile.WriteLine strComputer & ",OS," & i & ",Major Version, " & objItem.ServicePackMajorVersion objTextFile.WriteLine strComputer & ",OS," & i & ",Minor Version," & objItem.ServicePackMinorVersion ' objTextFile.WriteLine strComputer & ",OS," & i & ",Locale Settings," & LocalSetting objTextFile.WriteLine strComputer & ",OS," & i & ",Max Number Processors", objItem.MaxNumberOfProcesses i =i+1 Next i=1 ' Call function to find OU from computer name ou = getOUByComputerName(strComputer) IF ou = "" THEN ou = "Not Found" OUformatted= split(ou,",") OUOUT="" DCOUT="" for j = 0 to UBound(OUformatted) if left (OUformatted(j),2)="OU" then OUOUT=OUformatted(j) & OUOUT else DCOUT= DCOUT & OUformatted(j) end if next OUOUT=replace(ouout,"OU=","\") DCOUT=replace(DCOUT,"DC=",".") objTextFile.WriteLine strComputer & ",AD," & i & ",DOMAIN," & DCOUT objTextFile.WriteLine strComputer & ",AD," & i & ",OU," & OUOUT Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems objTextFile.WriteLine strComputer & ",Config," & i & ",Dell Assset Tag," & objItem.SerialNumber Next Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_IP4RouteTable where type=4", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) i=1 For Each objItem In colItems objTextFile.WriteLine strComputer & ",ROUTES," & i & ",Destination," & objItem.Destination objTextFile.WriteLine strComputer & ",ROUTES," & i & ",Mask," & objItem.Mask objTextFile.WriteLine strComputer & ",ROUTES," & i & ",Next Hop," & objItem.NextHop objTextFile.WriteLine strComputer & ",ROUTES," & i & ",protocol" & objItem.Protocol objTextFile.WriteLine strComputer & ",ROUTES," & i & ",type," & objItem.Type i=i+1 Next i=1 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFile", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems objTextFile.WriteLine strComputer & ",Page_File," & i & ",Create Date," & WMIDateStringToDate(objItem.CreationDate) objTextFile.WriteLine strComputer & ",Page_File," & i & ",Drive," & objItem.Drive objTextFile.WriteLine strComputer & ",Page_File," & i & ",File Name," & objItem.EightDotThreeFileName objTextFile.WriteLine strComputer & ",Page_File," & i & ",Free Space," & objItem.FreeSpace objTextFile.WriteLine strComputer & ",Page_File," & i & ",Initial Size," & objItem.InitialSize objTextFile.WriteLine strComputer & ",Page_File," & i & ",Install Date," & WMIDateStringToDate(objItem.InstallDate) objTextFile.WriteLine strComputer & ",Page_File," & i & ",Max Size," & objItem.MaximumSize Next i=1 sFile = "C:\windows\system32\drivers\etc\hosts" nCounter = 0 sComputer = "." Err.Clear Set refFile = GetObject("winMgmts:\\" & strComputer & "\root\cimv2:CIM_DataFile.Name='" & sFile & "'") If Err Then objTextFile.WriteLine strComputer & ",HOST_FILE," & i & ",HOST FILE Last changed,:ERROR Connecting" Else objTextFile.WriteLine strComputer & ",HOST_FILE ," & i & ",Host file last Changed," & WMIDateStringToDate(refFile.LastModified) End If set refFile = nothing i=1 Set colAdapters = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") For Each objAdapter in colAdapters objTextFile.WriteLine strComputer & ",Network," & i & ",MAC," & objAdapter.MACAddress & "," strIPAddress = Join(objAdapter.IPAddress, ",") objTextFile.WriteLine strComputer & ",Network," & i & ",IP," & strIPAddress & "," strDefaultIPGateway = Join(objAdapter.DefaultIPGateway, ",") objTextFile.WriteLine strComputer & ",Network," & i & ",Gateway," & strDefaultIPGateway & "," strDNSServerSearchOrder = Join(objAdapter.DNSServerSearchOrder, ",") strDNSServerSearchOrder=Replace(strDNSServerSearchOrder,",","/") objTextFile.WriteLine strComputer & ",Network," & i & ",DNS Search Order," & strDNSServerSearchOrder & "," strDNSDomainSuffixSearchOrder = Join(objAdapter.DNSDomainSuffixSearchOrder, ",") objTextFile.WriteLine strComputer & ",Network," & i & ",DNS Suffixes," & strDNSDomainSuffixSearchOrder & "," objTextFile.WriteLine strComputer & ",Network ," & i & ",SubNet," & Join(objAdapter.IPSubnet, ",") i = i +1 Next i=1 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * From Win32_PerfFormattedData_PerfOS_System") For Each objOS in colOperatingSystems intSystemUptime = Int(objOS.SystemUpTime / 60) intSystemUptime=round(intSystemUptime/60/24,0) objTextFile.WriteLine strComputer & ",Config ," & i & ",Server uptime in days," & intSystemUptime Next const HKEY_LOCAL_MACHINE = &H80000002 Set oReg=GetObject( _ "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "Software\Microsoft\MSDTC\Security\" strValueName = "NetworkDtcAccess" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessAdmin" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessClients" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessInbound" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessOutbound" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessTip" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strValueName = "NetworkDtcAccessTransactions" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strKeyPath = "Software\Microsoft\MSDTC\" strValueName = "AllowOnlySecureRpcCalls" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strKeyPath = "Software\Microsoft\MSDTC\" strValueName = "TurnOffRpcSecurity" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strKeyPath = "Software\Microsoft\MSDTC\" strValueName = "FallbackToUnsecureRPCIfNecessary" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strKeyPath = "Software\Microsoft\COM3\" strValueName = "RemoteAccessEnabled" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",MSDTC," & i &"," & strValueName & "," & dwValue strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\" strValueName = "DisableTaskOffload" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\" strValueName = "EnableTCPA" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\" strValueName = "EnableRSS" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\" strValueName = "EnableTCPChimney" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\" strValueName = "SusClientId" oReg.GetStringValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "System\CurrentControlSet\Services\xenevtchn\Parameters\" strValueName = "SetFlags" oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & dwValue strKeyPath = "SYSTEM\CurrentControlSet\Services\dcstor32\" strValueName = "DependOnService" oReg.GetMultiStringValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrValues For Each strValue In arrValues ObjTextfile.writeline StrComputer &",Registry," & i &"," & strValueName & "," & strValue Next ListOfKeys="" strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\Oc Manager\Subcomponents" oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_ arrValueNames, arrValueTypes For p=0 To UBound(arrValueNames) if ListOfKeys ="" then ListOfKeys= arrValueNames(p) Else ListOfKeys=ListOfKeys & "," & arrValueNames(p) end if Next KeysToCkeckArray=split(ListOfkeys,",") For p=0 To UBound(KeysToCkeckArray) strValueName =KeysToCkeckArray(p) oReg.GetDWORDValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue if dwValue = 0 then Else ObjTextfile.writeline StrComputer &",Components," & i &"," & strValueName & "," & dwValue End if Next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colSettings TotalMemory = round((objComputer.TotalPhysicalMemory/1024)/1024) ObjTextfile.writeline StrComputer &",Config," & i &",TOTAL MEMORY," & TotalMemory Next i=1 Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colSettings ObjTextfile.writeline StrComputer &",Config," & i &",Physical CPU COUNT," & objComputer.NumberOfProcessors ObjTextfile.writeline StrComputer &",Config," & i &",Total Cores," & objComputer.NumberOfLogicalProcessors ObjTextfile.writeline StrComputer &",Config," & i &",Server Model," & objComputer.Model ObjTextfile.writeline StrComputer &",Config," & i &",System Build Date," & WMIDateStringToDate(objComputer.InstallDate) i=i+1 Next i=1 Set objWMIService = GetObject(_ "winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery(_ "Select * from Win32_Processor") For Each objItem in colItems ObjTextfile.writeline StrComputer &",Config," & i &",CPU Speed," & objItem.MaxClockSpeed i=i+1 Next i=1 Set objWMIService=Nothing Set colAdapters=Nothing Set colItems=Nothing Set colSoftware =Nothing i=1 strComputer = strComputer Set objWMIService = GetObject( _ "winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery( _ "Select * from Win32_TimeZone") For Each objItem in colItems ObjTextfile.writeline StrComputer &",Config," & i &",Time Zone Description, " & objItem.Description ObjTextfile.writeline StrComputer &",Config," & i &",Time Zone DaylightName, " & objItem.DaylightName ObjTextfile.writeline StrComputer &",Config," & i &",Time Zone Standard Name, " & objItem.StandardName Next ObjTextfile.writeline StrComputer & ",END OF SERVER" '################################################################################################################################################# objTextFile.Close ' ############################### Function WMIDateStringToDate(dtmDate) WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _ Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _ & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2)) End Function function getOUByComputerName(byval computerName) ' *** Function to find ou/container of computer object from computer name *** DIM namingContext, ldapFilter, ou DIM cn, cmd, rs DIM objRootDSE ' Bind to the RootDSE to get the default naming context for ' the domain. e.g. dc=HCHS,dc=co,dc=uk set objRootDSE = getobject("LDAP://RootDSE") namingContext = objRootDSE.Get("defaultNamingContext") set objRootDSE = nothing ' Construct an ldap filter to search for a computer object ' anywhere in the domain with a name of the value specified. ldapFilter = "<LDAP://" & namingContext & _ ">;(&(objectCategory=Computer)(name=" & computerName & "))" & _ ";distinguishedName;subtree" ' Standard ADO code to query database set cn = createobject("ADODB.Connection") set cmd = createobject("ADODB.Command") cn.open "Provider=ADsDSOObject;" cmd.activeconnection = cn cmd.commandtext = ldapFilter set rs = cmd.execute if rs.eof <> true and rs.bof <> true then ou = rs(0) ' Convert distinguished name into OU. ' e.g. cn=CLIENT01,OU=HCHS_Computers,dc=HCHS,dc=co,dc=uk ' to: OU=HCHS_Computers,dc=HCHS,dc=co,dc=uk ou = mid(ou,instr(ou,",")+1,len(ou)-instr(ou,",")) getOUByComputerName = ou end if rs.close cn.close end function Function PingStatus(strComputer) On Error Resume Next strWorkstation = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2") Set colPings = objWMIService.ExecQuery ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'") For Each objPing in colPings ' wscript.echo PingStatus Select Case objPing.StatusCode Case 0 PingStatus = "Success" Case 11001 PingStatus = "Status code 11001 - Buffer Too Small" Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable" Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable" Case 11004 PingStatus = "Status code 11004 - Destination Protocol Unreachable" Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable" Case 11006 PingStatus = "Status code 11006 - No Resources" Case 11007 PingStatus = "Status code 11007 - Bad Option" Case 11008 PingStatus = "Status code 11008 - Hardware Error" Case 11009 PingStatus = "Status code 11009 - Packet Too Big" Case 11010 PingStatus = "Status code 11010 - Request Timed Out" Case 11011 PingStatus = "Status code 11011 - Bad Request" Case 11012 PingStatus = "Status code 11012 - Bad Route" Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit" Case 11014 PingStatus = "Status code 11014 - TimeToLive Expired Reassembly" Case 11015 PingStatus = "Status code 11015 - Parameter Problem" Case 11016 PingStatus = "Status code 11016 - Source Quench" Case 11017 PingStatus = "Status code 11017 - Option Too Big" Case 11018 PingStatus = "Status code 11018 - Bad Destination" Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC" Case 11050 PingStatus = "Status code 11050 - General Failure" Case Else PingStatus = "Status code " & objPing.StatusCode & " - Unable to determine cause of failure." End Select MsgBox (PingStatus) if PingStatus <> "Success" then Set WshShell = WScript.CreateObject("WScript.Shell") Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strComputer) 'send 3 echo requests, waiting 2secs eachstr PingResults = LCase(WshExec.StdOut.ReadAll) If InStr(strPingResults, "reply from") Then PingStatus = "Success" End If end if MsgBox (PingStatus) Next End Function Function FolderSize(TargetFolder) err.clear set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder(TargetFolder) If Err <> 0 Then fSize = err.description err.clear ' wscript.echo fSize Else fSize = Round(objFolder.Size/1024/1024) End If Err.Clear returnSize = fSize End Function

No comments:

Post a Comment