mindscape55
MIS
- Oct 12, 2012
- 1
New to VBscript simply trying to figure out how to have the output written to a CSV
On Error Resume Next
strComputer = "."
Set objSysInfo = CreateObject("ADSystemInfo")
strComputername = objSysInfo.Computername
Set objcomputer = GetObject("LDAP://" & strComputerName)
strOUName = objcomputer.Parent
Set objOU = GetObject(strOUName)
Wscript.Echo objOU.distinguishedName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Domain: " & objItem.Domain
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "Model: " & objItem.Model
WScript.Echo "Total Physical Memory: " & objItem.TotalPhysicalMemory
WScript.Echo "UserName: " & objItem.UserName
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "OS: " & objItem.Caption
WScript.Echo "Service Pack: " & objItem.CSDVersion
WScript.Echo "Build Date: " & WMIDateStringToDate(objItem.InstallDate)
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = 'True'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Description: " & objItem.Description
strIPAddress = Join(objItem.IPAddress, ",")
WScript.Echo "IP Address: " & strIPAddress
Next
WScript.Echo ("Done")
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
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
On Error Resume Next
strComputer = "."
Set objSysInfo = CreateObject("ADSystemInfo")
strComputername = objSysInfo.Computername
Set objcomputer = GetObject("LDAP://" & strComputerName)
strOUName = objcomputer.Parent
Set objOU = GetObject(strOUName)
Wscript.Echo objOU.distinguishedName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Domain: " & objItem.Domain
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "Model: " & objItem.Model
WScript.Echo "Total Physical Memory: " & objItem.TotalPhysicalMemory
WScript.Echo "UserName: " & objItem.UserName
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "OS: " & objItem.Caption
WScript.Echo "Service Pack: " & objItem.CSDVersion
WScript.Echo "Build Date: " & WMIDateStringToDate(objItem.InstallDate)
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = 'True'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Description: " & objItem.Description
strIPAddress = Join(objItem.IPAddress, ",")
WScript.Echo "IP Address: " & strIPAddress
Next
WScript.Echo ("Done")
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
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