Link to home
Create AccountLog in
Avatar of Ekuskowski
Ekuskowski

asked on

retrieving User name and computer name throughout domain

Does anyone know of a script that I can run that would return the computer name and username throughout my organization.

I need a list of everyon'es computername. So if I can get the Computername and username that was last logged in . i would be set

Thanks in advance for your help
Avatar of kuintencst
kuintencst

This works for me just change the file location and it should do the rest
'=======================================================================================================
'
' VBScript Source File
'
' NAME: Computer_Inventory.vbs
'
' AUTHOR: Kuinten Rucker
'         
'         
'         
'         
'
' DATE  : 5/21/2008
'
' COMMENT:  Collects various data and inputs into an Access Database
'           if database does not exist, it creates the Database (computer_inventory.mdb)
'           has option to check individual workstations or draw from a text file.
'           If text file doesn't exist, it creates an empty text file named servers.txt.
'           You still need to input the computer names in the text file and save it as
'           an ANSI text file.
'           If you choose the ALL option (draw from the text file) it is recommended that you
'           run the script as cscript or else you will be clicking OK for each computer on the list. 
'
'=======================================================================================================
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If Not objFSO.FileExists(".\computer_inventory.mdb") Then
 
Database()
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open _
    "Provider = Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source = computer_inventory.mdb" 
 
Else
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
 
objConnection.Open _
    "Provider = Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source = computer_inventory.mdb" 
 
 
 
Dim pcname,strPCName,strBNumber
 
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const HKEY_LOCAL_MACHINE = &H80000002
 
pcname = InputBox ("Please input a pc name, ip address or ALL to pull from a list of PC's", "PC name Input", "ALL")
  If Ucase(pcname) <> "ALL" Then
  strComputer = pcname
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
    If Err.Number <> 0 Then
objRecordSet.Open "SELECT * FROM Unavailable" , _
    objConnection, adOpenStatic, adLockOptimistic
objRecordSet.AddNew
objRecordSet("LookUpOn") = strComputer
objRecordSet("NotAvailable") = Err.Description
objRecordSet.Update
objRecordSet.Close
 
        Err.Clear
    Else
  WScript.Echo "Checking: " & strComputer
  Delete()
  Machine()
  Memory()
  Adapter()
  OperatingSystem()
  HotFix()
  Services()
  Software()
  PNP()
  VideoController()
  FreeSpace()
  Shares()
  Printer()
 End If
  Else
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If Not objFSO.FileExists(".\servers.txt") Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile _
    (".\servers.txt", 1, True)
    WScript.Echo "servers.txt created please populate with computer" & VbCrLf & _
    "names you want to query and save as an ANSI textfile."
    Quit()
Else
  Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(".\servers.txt", 1)
i = 0
 
Do Until objTextFile.AtEndOfStream 
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop
 
For Each objItem in objDictionary
    StrComputer = objDictionary.Item(objItem)
  WScript.Echo "Checking: " & strComputer
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
    If Err.Number <> 0 Then
'  WScript.Echo strComputer & vbTab & Err.Description
  objRecordSet.Open "SELECT * FROM Unavailable" , _
    objConnection, adOpenStatic, adLockOptimistic
objRecordSet.AddNew
objRecordSet("LookUpOn") = strComputer
objRecordSet("NotAvailable") = Err.Description
objRecordSet.Update
objRecordSet.Close
 
 
      Err.Clear
 
    Else
 
Delete()
Machine()
Memory()
Adapter()
OperatingSystem()
HotFix()
Services()
Software()
PNP()
VideoController()
FreeSpace()
Shares()
Printer()
End If
Next
End If
End If
End If
 
objConnection.Close
WScript.Echo "Inventory Completed"	
 
  Function Delete()
     Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
   For Each objItem In colItems
strPCName = objItem.Name
 
objRecordSet.Open "DELETE * FROM MachineProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
objRecordSet.Open "DELETE * FROM MemoryProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
objRecordSet.Open "DELETE * FROM NetworkProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
objRecordSet.Open "DELETE * FROM OperatingSystemProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM InstalledHotFixes WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM ServiceProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM ServiceProperties WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM InstalledSoftware WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM PlugNPlayDevices WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM VideoController WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM InstalledPrinters WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM FreeSpace WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
 objRecordSet.Open "DELETE * FROM NetworkShares WHERE " & _
    "ComputerName = '" & strPCName & "'", _
        objConnection, adOpenStatic, adLockOptimistic
Next  
  
  End Function
  
  Function Machine()
objRecordSet.Open "SELECT * FROM MachineProperties" , _
    objConnection, adOpenStatic, adLockOptimistic
 
 
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
   For Each objItem In colItems
strPCName = objItem.Name
objRecordSet.AddNew
      objRecordSet("ComputerName") = strPCName
      strAutomaticResetBootOption = Int(objItem.AutomaticResetBootOption)*-1
      If strAutomaticResetBootOption = 1 Then
      strAutomaticResetBootOption = "True"
      Else
      strAutomaticResetBootOption = "False"
      End If
      objRecordSet("AutomaticResetBootOption") = strAutomaticResetBootOption
      strAutomaticResetCapability = Int(objItem.AutomaticResetCapability)*-1
      If strAutomaticResetCapability = 1 then
      strAutomaticResetCapability = "True"
      Else
      strAutomaticResetCapability = "False"
      End If
      objRecordSet("AutomaticResetCapability") = strAutomaticResetCapability
      strBootROMSupported = Int(objItem.BootROMSupported)*-1
      If strBootROMSupported = 1 Then
      strBootROMSupported = "True"
      Else
      strBootROMSupported = "False"
      End If
      objRecordSet("BootROMSupported") = strBootROMSupported
      objRecordSet("BootupState") = objItem.BootupState
      objRecordSet("Caption") = objItem.Caption
      objRecordSet("CreationClassName") = objItem.CreationClassName
      objRecordSet("CurrentTimeZone") = objItem.CurrentTimeZone
      objRecordSet("Description") = objItem.Description
      objRecordSet("NetDomain") = objItem.Domain
      strinfraredsupported = Int(objItem.InfraredSupported)*-1
      If strinfraredsupported = 1 Then
      strinfraredsupported = "Yes"
      Else
      strinfraredsupported = "No"
      End If
      objRecordSet("InfraredSupported") = strinfraredsupported
      objRecordSet("Manufacturer") = objItem.Manufacturer
      objRecordSet("Model") = objItem.Model
      objRecordSet("Name") = objItem.Name
      strNetworkServerModeEnabled = Int(objItem.NetworkServerModeEnabled)*-1
      If strNetworkServerModeEnabled = 1 Then
      strNetworkServerModeEnabled = "True"
      Else
      strNetworkServerModeEnabled = "False"
      End If
      objRecordSet("NetworkServerModeEnabled") = strNetworkServerModeEnabled
      strPowerManagementSupported = Int(objItem.PowerManagementSupported)*-1
      If strPowerManagementSupported = 1 Then
      strPowerManagementSupported = "True"
      Else
      strPowerManagementSupported = "False"
      End If
      objRecordSet("PowerManagementSupported") = strPowerManagementSupported
      objRecordSet("PrimaryOwnerName") = objItem.PrimaryOwnerName
      strRoles = Join(objItem.Roles, ",")
       objRecordSet("Roles") = strRoles
      objRecordSet("Status") = objItem.Status
      objRecordSet("SystemStartupDelay") = objItem.SystemStartupDelay
      strSystemStartupOptions = Join(objItem.SystemStartupOptions, ",")
      objRecordSet("SystemStartupOptions") = strSystemStartupOptions
      objRecordSet("SystemStartupSetting") = objItem.SystemStartupSetting
      objRecordSet("SystemType") = objItem.SystemType
      objRecordSet("UserName") = objItem.UserName
      objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
   Next
objRecordSet.Close
End Function
 
Function Memory()
objRecordSet.Open "SELECT * FROM MemoryProperties" , _
    objConnection, adOpenStatic, adLockOptimistic
 
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
   For Each objItem In colItems
objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
      objRecordSet("Capacity") = objItem.Capacity
      objRecordSet("Caption") = objItem.Caption
      objRecordSet("CreationClassName") = objItem.CreationClassName
      objRecordSet("DataWidth") = objItem.DataWidth
      objRecordSet("Description") = objItem.Description
      objRecordSet("DeviceLocator") = objItem.DeviceLocator
      objRecordSet("FormFactor") = objItem.FormFactor
      objRecordSet("InterleaveDataDepth") = objItem.InterleaveDataDepth
      objRecordSet("InterleavePosition") = objItem.InterleavePosition
      objRecordSet("Manufacturer") = objItem.Manufacturer
      objRecordSet("MemoryType") = objItem.MemoryType
      objRecordSet("Model") = objItem.Model
      objRecordSet("Name") = objItem.Name
      objRecordSet("OtherIdentifyingInfo") = objItem.OtherIdentifyingInfo
      objRecordSet("PartNumber") = objItem.PartNumber
      objRecordSet("PositionInRow") = objItem.PositionInRow
      objRecordSet("PoweredOn") = objItem.PoweredOn
      objRecordSet("Removable") = objItem.Removable
      objRecordSet("Replaceable") = objItem.Replaceable
      objRecordSet("SerialNumber") = objItem.SerialNumber
      objRecordSet("SKU") = objItem.SKU
      objRecordSet("Speed") = objItem.Speed
      objRecordSet("Status") = objItem.Status
      objRecordSet("Tag") = objItem.Tag
      objRecordSet("TotalWidth") = objItem.TotalWidth
      objRecordSet("TypeDetail") = objItem.TypeDetail
      objRecordSet("Version") = objItem.Version
      objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
   Next
objRecordSet.Close
End Function
 
Function Adapter()
objRecordSet.Open "SELECT * FROM NetworkProperties" , _
    objConnection, adOpenStatic, adLockOptimistic
 
Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
n = 1
For Each objAdapter in colAdapters
   If Not IsNull(objAdapter.DHCPLeaseExpires) Then
      strLeaseExpires = WMIDateStringToDate(objAdapter.DHCPLeaseExpires)
   Else
      strLeaseExpires = Null
   End If
'If strLeaseExpires = "1/18/2038 10:14:07 PM" Then
'strLeaseExpires = Null
'End If
If strLeaseExpires >= Now Then
  objRecordSet.AddNew
    objRecordSet("ComputerName") = strPCName
   objRecordSet("AdapterSource") = "Network Adapter " & n
   objRecordSet("Description") = objAdapter.Description
 
   objRecordSet("Physical_MAC_address") = objAdapter.MACAddress
   objRecordSet("HostName") = objAdapter.DNSHostName
 
   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
         objRecordSet("IPAddress") = objAdapter.IPAddress(i)
   Next
   End If
 
   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
         objRecordSet("Subnet") = objAdapter.IPSubnet(i)
Next
   End If
 
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
         objRecordSet("DefaultGateway") = objAdapter.DefaultIPGateway(i)
   Next
   End If
 
 
   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      strDNSServerSearchOrder = Join(objAdapter.DNSServerSearchOrder, ",")
         objRecordSet("DNSServerSearchOrder") = strDNSServerSearchOrder
   End If
 
   objRecordSet("DNSDomain") = objAdapter.DNSDomain
   strDHCPEnabled = Int(objAdapter.DHCPEnabled)*-1
   If strDHCPEnabled = 1 Then
   strDHCPEnabled = "True"
   Else
   strDHCPEnabled = "False"
   End If
   objRecordSet("DHCPEnabled") = strDHCPEnabled
   objRecordSet("DHCPServer") = objAdapter.DHCPServer
 
   If Not IsNull(objAdapter.DHCPLeaseObtained) Then
      strLeaseObtained = WMIDateStringToDate(objAdapter.DHCPLeaseObtained)
   Else
      strLeaseObtained = ""
   End If
   objRecordSet("DHCPLeaseObtained") = strLeaseObtained
' WScript.Echo strPCName & vbTab & strLeaseExpires
   objRecordSet("DHCPLeaseExpires") = strLeaseExpires
   
   objRecordSet("PrimaryWINSServer") = objAdapter.WINSPrimaryServer
   objRecordSet("SecondaryWINSServer") = objAdapter.WINSSecondaryServer
      objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
 
   n = n + 1
End If 
Next
objRecordSet.Close
End Function
 
Function OperatingSystem()
objRecordSet.Open "SELECT * FROM OperatingSystemProperties" , _
    objConnection, adOpenStatic, adLockOptimistic
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
 
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
 
For Each objOperatingSystem in colOperatingSystems
     strBNumber = objOperatingSystem.BuildNumber
objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
    objRecordSet("SystemName") = objOperatingSystem.CSName
    objRecordSet("BootDevice") = objOperatingSystem.BootDevice
    objRecordSet("BuildNumber") = objOperatingSystem.BuildNumber
    objRecordSet("BuildType") = objOperatingSystem.BuildType
    objRecordSet("Caption") = objOperatingSystem.Caption
    objRecordSet("ServicePack") = objOperatingSystem.CSDVersion
    objRecordSet("CodeSet") = objOperatingSystem.CodeSet
    objRecordSet("CountryCode") = objOperatingSystem.CountryCode
    objRecordSet("Debug") = objOperatingSystem.Debug
    dtmConvertedDate.Value = objOperatingSystem.InstallDate
    dtmInstallDate = dtmConvertedDate.GetVarDate
    objRecordSet("InstallDate") = dtmInstallDate 
    objRecordSet("LicensedUsers") = _
        objOperatingSystem.NumberOfLicensedUsers
    objRecordSet("Organization") = objOperatingSystem.Organization
    objRecordSet("OSLanguage") = objOperatingSystem.OSLanguage
    objRecordSet("OSProductSuite") = objOperatingSystem.OSProductSuite
    objRecordSet("OSType") = objOperatingSystem.OSType
    objRecordSet("RegisteredUser") = objOperatingSystem.RegisteredUser
    objRecordSet("SerialNumber") = objOperatingSystem.SerialNumber
    objRecordSet("Version") = objOperatingSystem.Version
      objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
Next
objRecordSet.Close
End Function
 
Function HotFix()
objRecordSet.Open "SELECT * FROM InstalledHotFixes" , _
    objConnection, adOpenStatic, adLockOptimistic
 
     If strBNumber = "1381" Then
     
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Hotfix"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
For Each subkey In arrSubKeys
strsubkey = subkey
 
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Hotfix\" & subkey
oReg.EnumValues HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames, arrValueTypes
 
For Each ValueName In arrValueNames
oReg.GetStringValue  HKEY_LOCAL_MACHINE,strKeyPath,ValueName,strValue
Select Case ValueName
Case "Fix Description"
strdesc = strValue
Case "Installed On"
strInston = strValue
Case "Installed By"
strInstby = strValue
End Select
Next
 
'If strdesc <> "" Then
 
objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("HotFixID") = subkey
objRecordSet("Description") = strdesc
objRecordSet("InstallationDate") = strInston
objRecordSet("InstalledBy") = strInstby
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
strdesc = ""
strInston = ""
strInstby = ""
 
'End If
 
Next
 
Else
 
 
Set colQuickFixes = objWMIService.ExecQuery _
    ("Select * from Win32_QuickFixEngineering")
 
For Each objQuickFix in colQuickFixes
    If objQuickFix.HotFixID <> "File 1" Then
objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("HotFixID") = objQuickFix.HotFixID
objRecordSet("Description") = objQuickFix.Description
objRecordSet("InstallationDate") = objQuickFix.InstallDate
objRecordSet("InstalledBy") = objQuickFix.InstalledBy
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
End If
Next
End If
objRecordSet.Close
End Function
 
Function Services()
objRecordSet.Open "SELECT * FROM ServiceProperties" , _
    objConnection, adOpenStatic, adLockOptimistic
Set colListOfServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service")
 
For Each objService in colListOfServices
objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("SystemName") = objService.SystemName 
objRecordSet("ServiceName") = objService.Name
objRecordSet("ServiceType") = objService.ServiceType 
objRecordSet("ServiceState") = objService.State 
objRecordSet("ExitCode") = objService.ExitCode 
objRecordSet("ProcessID") = objService.ProcessID
strAcceptPause = Int(objService.AcceptPause)*-1
If strAcceptPause = 1 Then
strAcceptPause = "True"
Else
strAcceptPause = "False"
End If
objRecordSet("CanBePaused") =  strAcceptPause
strAcceptStop = Int(objService.AcceptStop)*-1
If strAcceptStop = 1 Then
strAcceptStop = "True"
Else
strAcceptStop = "False"
End If
objRecordSet("CanBeStopped") = strAcceptStop
objRecordSet("Caption") = objService.Caption 
objRecordSet("Description") = Left(objService.Description , 255)
strDesktopInteract = Int(objService.DesktopInteract)*-1
If strDesktopInteract = 1 Then
strDesktopInteract = "True"
Else
strDesktopInteract = "False"
End If
objRecordSet("CanInteractWithDesktop") =  strDesktopInteract
objRecordSet("DisplayName") = objService.DisplayName 
objRecordSet("ErrorControl") = objService.ErrorControl 
objRecordSet("ExecutablePathName") = objService.PathName
 strStarted = Int(objService.Started)*-1
 If strStarted = 1 Then
 strStarted = "Yes"
 Else
 strStarted = "No"
 End If
objRecordSet("ServiceStarted") =  strStarted
objRecordSet("StartMode") = objService.StartMode 
objRecordSet("AccountName") = objService.StartName 
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
Next
objRecordSet.Close
End Function
 
Function Software()
On Error Resume Next
objRecordSet.Open "SELECT * FROM InstalledSoftware" , _
    objConnection, adOpenStatic, adLockOptimistic
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
For Each subkey In arrSubKeys
strsubkey = subkey
strValueName = "DisplayName"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & strsubkey
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If IsNull(strValue)  Then
strValue = strsubkey
End If
  objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("SoftwareSubKey") = strsubkey
objRecordSet("DisplayName") = strValue
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
Next
objRecordSet.Close
End Function
 
Function PNP()
objRecordSet.Open "SELECT * FROM PlugNPlayDevices" , _
    objConnection, adOpenStatic, adLockOptimistic
 
Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity")
 
For Each objItem in colItems
     objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("ClassGUID") = objItem.ClassGuid
objRecordSet("Description") = objItem.Description
objRecordSet("DeviceID") = objItem.DeviceID
objRecordSet("Manufacturer") = objItem.Manufacturer
objRecordSet("Name") = objItem.Name
objRecordSet("PNPDeviceID") = objItem.PNPDeviceID
objRecordSet("Service") = objItem.Service
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
Next
objRecordSet.Close
End Function
 
Function VideoController()
objRecordSet.Open "SELECT * FROM VideoController" , _
    objConnection, adOpenStatic, adLockOptimistic
 
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_VideoController")
 
For Each objItem in colItems
       objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("AdapterCompatibility") = objItem.AdapterCompatibility
objRecordSet("AdapterDACType") = objItem.AdapterDACType
objRecordSet("AdapterRAM") = objItem.AdapterRAM
objRecordSet("Availability") = objItem.Availability
objRecordSet("ColorTableEntries") = objItem.ColorTableEntries
objRecordSet("CurrentBitsPerPixel") = objItem.CurrentBitsPerPixel
objRecordSet("CurrentHorizontalResolution") = objItem.CurrentHorizontalResolution
objRecordSet("CurrentNumberofColors") = objItem.CurrentNumberOfColors
objRecordSet("CurrentNumberofColumns") = objItem.CurrentNumberOfColumns
objRecordSet("CurrentNumberofRows") = objItem.CurrentNumberOfRows
objRecordSet("CurrentRefreshRate") = objItem.CurrentRefreshRate
objRecordSet("CurrentScanMode") = objItem.CurrentScanMode
objRecordSet("CurrentVerticalResolution") = objItem.CurrentVerticalResolution
objRecordSet("Description") = objItem.Description
objRecordSet("DeviceID") = objItem.DeviceID
strDeviceSpecificPens = Int(objItem.DeviceSpecificPens)*-1
If strDeviceSpecificPens = 1 Then
strDeviceSpecificPens = "Yes"
Else
strDeviceSpecificPens = "No"
End If
objRecordSet("DeviceSpecificPens") = strDeviceSpecificPens
objRecordSet("DitherType") = objItem.DitherType
objRecordSet("DriverDate") = objItem.DriverDate
objRecordSet("DriverVersion") = objItem.DriverVersion
objRecordSet("ICMIntent") = objItem.ICMIntent
objRecordSet("ICMMethod") = objItem.ICMMethod
objRecordSet("INFFilename") = objItem.InfFilename
objRecordSet("INFSection") = objItem.InfSection
objRecordSet("InstalledDisplayDrivers") = objItem.InstalledDisplayDrivers
objRecordSet("MaximumMemorySupported") = objItem.MaxMemorySupported
objRecordSet("MaximumNumberControlled") = objItem.MaxNumberControlled
objRecordSet("MaximumRefreshRate") = objItem.MaxRefreshRate
objRecordSet("MinimumRefreshRate") = objItem.MinRefreshRate
objRecordSet("Monochrome") = objItem.Monochrome
objRecordSet("Name") = objItem.Name
objRecordSet("NumberofColorPlanes") = objItem.NumberOfColorPlanes
objRecordSet("NumberofVideoPages") = objItem.NumberOfVideoPages
objRecordSet("PNPDeviceID") = objItem.PNPDeviceID
objRecordSet("ReservedSystemPaletteEntries") = objItem.ReservedSystemPaletteEntries
objRecordSet("SpecificationVersion") = objItem.SpecificationVersion
objRecordSet("SystemPaletteEntries") = objItem.SystemPaletteEntries
objRecordSet("VideoArchitecture") = objItem.VideoArchitecture
objRecordSet("VideoMemoryType") = objItem.VideoMemoryType
objRecordSet("VideoMode") = objItem.VideoMode
objRecordSet("VideoModeDescription") = objItem.VideoModeDescription
objRecordSet("VideoProcessor") = objItem.VideoProcessor
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
 
Next
objRecordSet.Close
End Function
 
Function Printer()
objRecordSet.Open "SELECT * FROM InstalledPrinters" , _
    objConnection, adOpenStatic, adLockOptimistic
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "System\CurrentControlSet\Control\Print\Printers"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
If IsNull(arrSubKeys) Then
strName = "No Printers Installed"
     objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("PrinterName") = strName
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
Else
 
For Each subkey In arrSubKeys
 
strKeyPath = "System\CurrentControlSet\Control\Print\Printers\" & subkey
oReg.EnumValues HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames, arrValueTypes
If Not IsNull(arrValueNames) Then
 
For Each ValueName In arrValueNames
oReg.GetStringValue  HKEY_LOCAL_MACHINE,strKeyPath,ValueName,strValue
Select Case ValueName
Case "Datatype"
strdatatype = strValue
Case "Default Priority"
strDefault = dwValue
Case "Description"
strdescription = strValue
Case "Location"
strLocation = strValue
Case "Name"
strName = strValue
Case "Port"
strPort = strValue
Case "Print Processor"
strProcessor = strValue
Case "Printer Driver"
strDriver = strValue
Case "Priority"
strPriority = dwValue
Case "Separator File"
strSeparator = strValue
End Select
Next
 
     objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("PrinterName") = strName
objRecordSet("PrinterModel") = strDriver
objRecordSet("Description") = strdescription
objRecordSet("Port") = strPort
objRecordSet("Priority") = strPriority
objRecordSet("PrintProcessor") = strProcessor
objRecordSet("SeparatorFile") = strSeparator
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
End If
Next
End If
objRecordSet.Close
End Function
 
Function FreeSpace()
objRecordSet.Open "SELECT * FROM FreeSpace" , _
    objConnection, adOpenStatic, adLockOptimistic
Const HARD_DISK = 3
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
 
For Each objDisk in colDisks
IntUsed = (objDisk.Size - objDisk.FreeSpace)
IntFKB = (objDisk.FreeSpace / "1024")
IntFMB = (intFKB / "1024")
IntFGB = (intFMB / "1024")
IntSKB = (objDisk.Size / "1024")
IntSMB = (IntSKB / "1024")
IntSGB = (IntSMB / "1024")
IntUKB = (IntUsed / "1024")
IntUMB = (IntUKB / "1024")
IntUGB = (IntUMB / "1024")
IntpctUsed = Left(((intUsed / objDisk.Size) * 100), 5)
IntpctFree = Left(((objDisk.FreeSpace / objDisk.Size) * 100), 5)
If IntFKB < 1 Then
strFreeSpace = objDisk.FreeSpace & " Bytes"
ElseIf IntFMB < 1 Then
StrFreeSpace = Left(IntFKB, 7) & " KB"
ElseIf IntFGB < 1 Then
strFreeSpace = Left(IntFMB, 7) & " MB"
Else
strFreeSpace = Left(IntFGB, 7) & " GB"
End If
If IntSKB < 1 Then
strSize = objDisk.Size & " Bytes"
Elseif IntSMB < 1 Then
strSize = Left(IntSKB, 7) & " KB"
Elseif IntSGB < 1 Then
StrSize = Left(IntSMB, 7) & " MB"
Else
strSize = Left(IntSGB, 7) & " GB"
End If
If IntUKB < 1 Then
strUsed = Left(IntUsed, 7) & " Bytes"
ElseIf IntUMB < 1 Then
strUsed = Left(IntUKB, 7) & " KB"
ElseIf IntUGB < 1 Then
strUsed = Left(IntUMB, 7) & " MB"
Else
strUsed = Left(IntUGB, 7) & " GB"
End If 
 
     objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
objRecordSet("DeviceID") =  objDisk.DeviceID
objRecordSet("DiskSize") = strSize       
objRecordSet("UsedSpace") = strUsed
objRecordSet("FreeDiskSpace") = strFreeSpace
objRecordSet("PercentUsed") = IntpctUsed & "%"
objRecordSet("PercentFree") = IntpctFree & "%"
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
 
Next
objRecordSet.Close
End Function
 
Function Shares()
objRecordSet.Open "SELECT * FROM NetworkShares" , _
    objConnection, adOpenStatic, adLockOptimistic
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
 
For each objShare in colShares
     objRecordSet.AddNew
objRecordSet("ComputerName") = strPCName
strAllowMaximum = Int(objShare.AllowMaximum)*-1
If strAllowMaximum = 1 Then
strAllowMaximum = "True"
Else
strAllowMaximum = "False"
End If
objRecordSet("AllowMaximum") = strAllowMaximum   
objRecordSet("Caption") = objShare.Caption   
objRecordSet("MaximumAllowed") = objShare.MaximumAllowed
objRecordSet("Name") = objShare.Name   
objRecordSet("Path") = objShare.Path   
objRecordSet("LookUpOn") = strComputer
objRecordSet.Update
 
Next
objRecordSet.Close
End Function
 
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
 
Sub Database()
 
Set objConn = CreateObject("ADOX.Catalog")
 
objConn.Create _
    "Provider = Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source = computer_inventory.mdb"
        WScript.Sleep 3000
        
Set objConn = CreateObject("ADODB.Connection")
 
objConn.Open _
    "Provider= Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source=computer_inventory.mdb" 
 
objConn.Execute "CREATE TABLE FreeSpace(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "DeviceID TEXT(50) ," & _
    "DiskSize TEXT(255) ," & _
    "UsedSpace TEXT(255) ," & _
    "FreeDiskSpace TEXT(255) ," & _
    "PercentUsed TEXT(255) ," & _
    "PercentFree TEXT(255) ," & _
    "LookUpOn TEXT(255))"
    
objConn.Execute "CREATE TABLE InstalledHotFixes(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "HotFixID TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "ServicePackInEffect TEXT(255) ," & _
    "InstallationDate TEXT(255) ," & _
    "InstalledBy TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE InstalledPrinters(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "PrinterName TEXT(255) ," & _
    "PrinterModel TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "Port TEXT(255) ," & _
    "Priority TEXT(255) ," & _
    "PrintProcessor TEXT(255) ," & _
    "SeparatorFile TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE MachineProperties(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "Caption TEXT(255) ," & _
    "Model TEXT(255) ," & _
    "UserName TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "SystemStartupOptions TEXT(255) ," & _
    "AutomaticResetBootOption TEXT(255) ," & _
    "AutomaticResetCapability TEXT(255) ," & _
    "BootROMSupported TEXT(255) ," & _
    "BootupState TEXT(255) ," & _
    "CreationClassName TEXT(255) ," & _
    "CurrentTimeZone TEXT(255) ," & _
    "NetDomain TEXT(255) ," & _
    "InfraredSupported TEXT(255) ," & _
    "Manufacturer TEXT(255) ," & _
    "Name TEXT(255) ," & _
    "NetworkServerModeEnabled TEXT(255) ," & _
    "PowerManagementSupported TEXT(255) ," & _
    "PrimaryOwnerName TEXT(255) ," & _
    "Roles TEXT(255) ," & _
    "Status TEXT(255) ," & _
    "SystemStartupDelay TEXT(255) ," & _
    "SystemStartupSetting TEXT(255) ," & _
    "SystemType TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE MemoryProperties(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "Capacity TEXT(255) ," & _
    "Caption TEXT(255) ," & _
    "CreationClassName TEXT(255) ," & _
    "DataWidth TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "DeviceLocator TEXT(255) ," & _
    "FormFactor TEXT(255) ," & _
    "InterleaveDataDepth TEXT(255) ," & _
    "InterleavePosition TEXT(255) ," & _
    "Manufacturer TEXT(255) ," & _
    "MemoryType TEXT(255) ," & _
    "Model TEXT(255) ," & _
    "Name TEXT(255) ," & _
    "OtherIdentifyingInfo TEXT(255) ," & _
    "PowerManagementSupported TEXT(255) ," & _
    "PartNumber TEXT(255) ," & _
    "PositionInRow TEXT(255) ," & _
    "PoweredOn TEXT(255) ," & _
    "Removable TEXT(255) ," & _
    "Replaceable TEXT(255) ," & _
    "SerialNumber TEXT(255) ," & _
    "SKU TEXT(255) ," & _
    "Speed TEXT(255) ," & _
    "Status TEXT(255) ," & _
    "Tag TEXT(255) ," & _
    "TotalWidth TEXT(255) ," & _
    "TypeDetail TEXT(255) ," & _
    "Version TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE NetworkProperties(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "AdapterSource TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "Physical_MAC_address TEXT(255) ," & _
    "HostName TEXT(255) ," & _
    "IPAddress TEXT(255) ," & _
    "Subnet TEXT(255) ," & _
    "DefaultGateway TEXT(255) ," & _
    "DNSServerSearchOrder TEXT(255) ," & _
    "DNSDomain TEXT(255) ," & _
    "DHCPEnabled TEXT(255) ," & _
    "DHCPServer TEXT(255) ," & _
    "DHCPLeaseObtained TEXT(255) ," & _
    "DHCPLeaseExpires TEXT(255) ," & _
    "PrimaryWINSServer TEXT(255) ," & _
    "SecondaryWINSServer TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE NetworkShares(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "AllowMaximum TEXT(255) ," & _
    "Caption TEXT(255) ," & _
    "MaximumAllowed TEXT(255) ," & _
    "Name TEXT(255) ," & _
    "Path TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE OperatingSystemProperties(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "SystemName TEXT(255) ," & _
    "Caption TEXT(255) ," & _
    "BuildNumber TEXT(255) ," & _
    "BootDevice TEXT(255) ," & _
    "BuildType TEXT(255) ," & _
    "ServicePack TEXT(255) ," & _
    "CodeSet TEXT(255) ," & _
    "CountryCode TEXT(255) ," & _
    "Debug TEXT(255) ," & _
    "InstallDate TEXT(255) ," & _
    "LicensedUsers TEXT(255) ," & _
    "Organization TEXT(255) ," & _
    "OSLanguage TEXT(255) ," & _
    "OSProductSuite TEXT(255) ," & _
    "OSType TEXT(255) ," & _
    "RegisteredUser TEXT(255) ," & _
    "SerialNumber TEXT(255) ," & _
    "Version TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE PlugNPlayDevices(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "Name TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "ClassGUID TEXT(255) ," & _
    "DeviceID TEXT(255) ," & _
    "Manufacturer TEXT(255) ," & _
    "PNPDeviceID TEXT(255) ," & _
    "Service TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE ServiceProperties(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "SystemName TEXT(255) ," & _
    "ServiceName TEXT(255) ," & _
    "ServiceType TEXT(255) ," & _
    "ServiceState TEXT(255) ," & _
    "ExitCode TEXT(255) ," & _
    "ProcessID TEXT(255) ," & _
    "CanBePaused TEXT(255) ," & _
    "CanBeStopped TEXT(255) ," & _
    "Caption TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "CanInteractWithDesktop TEXT(255) ," & _
    "DisplayName TEXT(255) ," & _
    "ErrorControl TEXT(255) ," & _
    "ExecutablePathName TEXT(255) ," & _
    "ServiceStarted TEXT(255) ," & _
    "StartMode TEXT(255) ," & _
    "AccountName TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE InstalledSoftware(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "SoftwareSubKey TEXT(255) ," & _
    "DisplayName TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE Unavailable(" & _
    "ID COUNTER ," & _
    "LookUpOn TEXT(50) ," & _
    "NotAvailable TEXT(255))"
 
objConn.Execute "CREATE TABLE VideoController(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "Name TEXT(255) ," & _
    "Description TEXT(255) ," & _
    "AdapterCompatibility TEXT(255) ," & _
    "AdapterDACType TEXT(255) ," & _
    "AdapterRAM TEXT(255) ," & _
    "Availability TEXT(255) ," & _
    "ColorTableEntries TEXT(255) ," & _
    "CurrentBitsPerPixel TEXT(255) ," & _
    "CurrentHorizontalResolution TEXT(255) ," & _
    "CurrentVerticalResolution TEXT(255) ," & _
    "CurrentNumberofColors TEXT(255) ," & _
    "CurrentNumberofColumns TEXT(255) ," & _
    "CurrentNumberofRows TEXT(255) ," & _
    "CurrentRefreshRate TEXT(255) ," & _
    "CurrentScanMode TEXT(255) ," & _
    "DeviceID TEXT(255) ," & _
    "DeviceSpecificPens TEXT(255) ," & _
    "DitherType TEXT(255) ," & _
    "DriverDate TEXT(255) ," & _
    "DriverVersion TEXT(255) ," & _
    "ICMIntent TEXT(255) ," & _
    "ICMMethod TEXT(255) ," & _
    "INFFilename TEXT(255) ," & _
    "INFSection TEXT(255) ," & _
    "InstalledDisplayDrivers TEXT(255) ," & _
    "MaximumMemorySupported TEXT(255) ," & _
    "MaximumNumberControlled TEXT(255) ," & _
    "MaximumRefreshRate TEXT(255) ," & _
    "MinimumRefreshRate TEXT(255) ," & _
    "Monochrome TEXT(255) ," & _
    "NumberofColorPlanes TEXT(255) ," & _
    "NumberofVideoPages TEXT(255) ," & _
    "PNPDeviceID TEXT(255) ," & _
    "ReservedSystemPaletteEntries TEXT(255) ," & _
    "SpecificationVersion TEXT(255) ," & _
    "SystemPaletteEntries TEXT(255) ," & _
    "VideoArchitecture TEXT(255) ," & _
    "VideoMemoryType TEXT(255) ," & _
    "VideoMode TEXT(255) ," & _
    "VideoModeDescription TEXT(255) ," & _
    "VideoProcessor TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Execute "CREATE TABLE UserInfo(" & _
    "ID COUNTER ," & _
    "ComputerName TEXT(50) ," & _
    "IPAddress TEXT(255) ," & _
    "FirstName TEXT(255) ," & _
    "LastName TEXT(255) ," & _
    "PhoneNumber TEXT(255) ," & _
    "ImmediateSupervisorFirst TEXT(255) ," & _
    "ImmediateSupervisorLast TEXT(255) ," & _
    "Building TEXT(255) ," & _
    "Floor TEXT(255) ," & _
    "Wing TEXT(255) ," & _
    "LookUpOn TEXT(255))"
 
objConn.Close
WScript.Echo "computer_inventory.mdb not found so it was created" & VbCrLf & _
              "Please restart the Script"
End Sub

Open in new window

Avatar of Ekuskowski

ASKER

OK, so I'mn not exactly sure what location I need to change and what I am supposed to do with this code.
this is a .vbs save this in a .txt file and change the extension
you should be able to just save it and run it, I got this from another person at my job
I was actually hoping for a script that will go out and create a list of all the usernames and computer names, I don't want to have to provide the names of the computers. Unless there is an easy way for me to creAte a list of all the computer names in our organization.

Thanks again
Avatar of robsantos

Do you mean something like this (from http://technet2.microsoft.com/windowsserver/en/library/539c5381-db4f-445f-aac0-2df5448181c11033.mspx?mfr=true)

View All Workstation Members in a Domain
To list all the workstations in the domain Northamerica, type the following at the command prompt:
netdom query /d:Northamerica WORKSTATION
Does that get you halfway there?
ok I ran the net dom Query I wrote it to a text file. I then cleaned up the text file and used when running the vbs script.

The VBS script creates a database but it does not show me the last person logged into the computer.

Does anyone know how to modify this script or have another script that can produce workstation names and logged on username.

I figure Active directory must have this information, I just don't know how to access it.

Any help is much appreciated.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of robsantos
robsantos

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer