sted Posted March 30, 2012 Posted March 30, 2012 notes the pcs account needs to be able to write to its own description field in active directory (easily done with delegate control to either domain pcs or as i do an allpcs group containing domain pcs (as i dont like delegating control to a built in group) needs a share on network somewhere that auth users can write to in the main script its \\server\log$\pcs\ and the obvious disclaimer ive not had any issues but that dosent mean you wont so use it at your own risk records basic details in ad (make model, cpu,ram,hdd,serial, mac(s) basically stuff that dosent change often) and if you have existing info in the computers description before deploying the script add a # before it (so if your description field said staffab laptop change to #staffab laptop before deploying script) and it will keep that there (though the data after will not update after the first time until you manually remove the # at the very end of the line) it now only writes to ad when a change is detected it creates a csv file with more info in it in the format below (and copy and past that to a file called 01.csv if you want a nice formatted spreadsheet of all pcs make-model,cpu,ram,hdd size,hdd free,serial no,Windows Version,mac address(es),Windows experience ratings,last user,Network Speed,date collected the following batch file will concatenate all the individual files into 1 file (needs to be a drive letter you run it from not a unc path del all.csv /q copy "*.csv" "all.csv" /y main code itself Option Explicit 'On Error Resume Next dim outputstring, computermodel, cpu, ram, hddcapacity, hddfree, serialno, macaddress, operatingsystem, csvoutput dim stcomputer, colitems, objItem, colcpu, colPhysicalMemory, objPhysicalMemory, intMemory, colDisks, objhdd dim colComputerSystem, colOperatingSystems, objOperatingSystem, colBIOS, objBIOS, colnicconfig, objnicconfig dim objwmiservice, hddtemp, weidata, colWSA, operatingsystemno, Lastuser, oreg, spath, svalue, strvalue, svaluename dim adoutputstring, adoRecordset, adoConnection, objRootDSE, objNetwork, objComputer, existing dim pcname, wshShell, strDirectory, strFile, objFSO, objFolder, objFile, objTextFile, myDateString dim colnet,objnet, linkspeed, objWMIService2 stcomputer = "." myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("winmgmts:\\" & stcomputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") Set colnicconfig = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") Set colWSA = objWMIservice.ExecQuery("Select * From Win32_WinSAT") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objWMIService2 = GetObject("winmgmts:\\" & stComputer & "\root\WMI") Set colnet = objWMIService2.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48) 'write file location pcname = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) strDirectory = "\\server\log$\pcs\" strFile = pcname & ".csv" 'make-model For Each objItem In colItems computermodel= objItem.Manufacturer & " " & objItem.Model 'wscript.echo computermodel Next ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'cpu info For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 ) & " MB" 'wscript.echo ram End If 'hdd capacity for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next 'windows version For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version 'wscript.echo operatingsystem Next 'serial no If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'mac address(s) If Not colnicconfig Is Nothing Then For Each objnicconfig in colnicconfig If macaddress <> "" Then macaddress = macaddress & " - " End If macaddress = macaddress & objnicconfig.MACAddress 'wscript.echo macaddress Next End If 'windows experience operatingsystemno = Left( operatingsystemno, 3 ) if operatingsystemno >5.5 then 'vista+ For Each objItem in colWSA 'weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" weidata = "Overall -" & objItem.WinSPRLevel & " - CPU - " & objItem.CPUScore & " - Memory - " & objItem.MemoryScore & " - Graphics - " & objItem.GraphicsScore & " - Gaming graphics - " & objItem.D3DScore & " - hdd - " & objItem.DiskScore next else 'xp- weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" end if 'last user if operatingsystemno >5.5 then 'vista+ Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & stcomputer & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & stcomputer End If End If else 'xp- Const HKEY_LOCAL_MACHINE = &H80000002 Set oreg=GetObject("winmgmts:\\" & stComputer & "\root\default:StdRegProv") spath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" svalue = "DefaultUserName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser=strvalue svalue = "DefaultDomainName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser = strvalue & "\" & lastuser end if 'Scans data for Net Speed For Each objnet in colnet 'Removes "slow/unused links" if objnet.NdisLinkSpeed/10 > 1000 then linkspeed= objnet.NdisLinkSpeed/10000 & " Mbps" & "-" & linkspeed '& "-" & objnet.NdisLinkSpeed/10000 & " Mbps" end if next 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," csvoutput = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & hddfree & "," & serialno & "," & operatingsystem & "," & macaddress & "," & weidata & "," & Lastuser & "," & linkspeed &"," & myDateString &"," ' wscript.echo outputstring ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) 'WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 2 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes result every time you run this VBScript objTextFile.WriteLine(csvoutput) objTextFile.Close If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) existing = objcomputer.Description if left (existing,1) = "#" and not right (existing,1) = "#" then outputstring = existing & " : " & outputstring & "#" if left (existing,1) = "#" and right (existing,1) = "#" then 'msgbox "data" wscript.quit end if if not objComputer.Description = outputstring then 'msgbox "diff" objComputer.Put "description", outputstring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If
sted Posted April 2, 2012 Author Posted April 2, 2012 repost as i forgot to put the pcs name in the csv file whichh made it a bit pointless lol (and for some reason i cant edit the old post) notes the pcs account needs to be able to write to its own description field in active directory (easily done with delegate control to either domain pcs or as i do an allpcs group containing domain pcs (as i dont like delegating control to a built in group) needs a share on network somewhere that auth users can write to in the main script its \\server\log$\pcs\ and the obvious disclaimer ive not had any issues but that dosent mean you wont so use it at your own risk records basic details in ad (make model, cpu,ram,hdd,serial, mac(s) basically stuff that dosent change often) and if you have existing info in the computers description before deploying the script add a # before it (so if your description field said staffab laptop change to #staffab laptop before deploying script) and it will keep that there (though the data after will not update after the first time until you manually remove the # at the very end of the line) it now only writes to ad when a change is detected it creates a csv file with more info in it in the format below (and copy and past that to a file called 01.csv if you want a nice formatted spreadsheet of all pcs name,make-model,cpu,ram,hdd size,hdd free,serial no,Windows Version,mac address(es),Windows experience ratings,last user,Network Speed,date collected the following batch file will concatenate all the individual files into 1 file (needs to be a drive letter you run it from not a unc path del all.csv /q copy "*.csv" "all.csv" /y main code itself Option Explicit 'On Error Resume Next dim outputstring, computermodel, cpu, ram, hddcapacity, hddfree, serialno, macaddress, operatingsystem, csvoutput dim stcomputer, colitems, objItem, colcpu, colPhysicalMemory, objPhysicalMemory, intMemory, colDisks, objhdd dim colComputerSystem, colOperatingSystems, objOperatingSystem, colBIOS, objBIOS, colnicconfig, objnicconfig dim objwmiservice, hddtemp, weidata, colWSA, operatingsystemno, Lastuser, oreg, spath, svalue, strvalue, svaluename dim adoutputstring, adoRecordset, adoConnection, objRootDSE, objNetwork, objComputer, existing dim pcname, wshShell, strDirectory, strFile, objFSO, objFolder, objFile, objTextFile, myDateString dim colnet,objnet, linkspeed, objWMIService2 stcomputer = "." myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("winmgmts:\\" & stcomputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") Set colnicconfig = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") Set colWSA = objWMIservice.ExecQuery("Select * From Win32_WinSAT") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objWMIService2 = GetObject("winmgmts:\\" & stComputer & "\root\WMI") Set colnet = objWMIService2.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48) 'write file location pcname = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) strDirectory = "\\server\log$\pcs\" strFile = pcname & ".csv" 'make-model For Each objItem In colItems computermodel= objItem.Manufacturer & " " & objItem.Model 'wscript.echo computermodel Next ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'cpu info For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 ) & " MB" 'wscript.echo ram End If 'hdd capacity for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next 'windows version For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version 'wscript.echo operatingsystem Next 'serial no If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'mac address(s) If Not colnicconfig Is Nothing Then For Each objnicconfig in colnicconfig If macaddress <> "" Then macaddress = macaddress & " - " End If macaddress = macaddress & objnicconfig.MACAddress 'wscript.echo macaddress Next End If 'windows experience operatingsystemno = Left( operatingsystemno, 3 ) if operatingsystemno >5.5 then 'vista+ For Each objItem in colWSA 'weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" weidata = "Overall -" & objItem.WinSPRLevel & " - CPU - " & objItem.CPUScore & " - Memory - " & objItem.MemoryScore & " - Graphics - " & objItem.GraphicsScore & " - Gaming graphics - " & objItem.D3DScore & " - hdd - " & objItem.DiskScore next else 'xp- weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" end if 'last user if operatingsystemno >5.5 then 'vista+ Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & stcomputer & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & stcomputer End If End If else 'xp- Const HKEY_LOCAL_MACHINE = &H80000002 Set oreg=GetObject("winmgmts:\\" & stComputer & "\root\default:StdRegProv") spath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" svalue = "DefaultUserName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser=strvalue svalue = "DefaultDomainName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser = strvalue & "\" & lastuser end if 'Scans data for Net Speed For Each objnet in colnet 'Removes "slow/unused links" if objnet.NdisLinkSpeed/10 > 1000 then linkspeed= objnet.NdisLinkSpeed/10000 & " Mbps" & "-" & linkspeed '& "-" & objnet.NdisLinkSpeed/10000 & " Mbps" end if next 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," csvoutput = pcname & "," & computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & hddfree & "," & serialno & "," & operatingsystem & "," & macaddress & "," & weidata & "," & Lastuser & "," & linkspeed &"," & myDateString &"," ' wscript.echo outputstring ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) 'WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 2 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes result every time you run this VBScript objTextFile.WriteLine(csvoutput) objTextFile.Close If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) existing = objcomputer.Description if left (existing,1) = "#" and not right (existing,1) = "#" then outputstring = existing & " : " & outputstring & "#" if left (existing,1) = "#" and right (existing,1) = "#" then 'msgbox "data" wscript.quit end if if not objComputer.Description = outputstring then 'msgbox "diff" objComputer.Put "description", outputstring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If 3
linkazoid Posted February 9, 2015 Posted February 9, 2015 @sted Do you have an updated version of this? I'm looking for a script that will output the following to the AD Descripton field. - Model, SSD, RAM total, lasted logged on. The rest of the data can be logged in the CSV. Hope someone can help. Thanks, Michael
sted Posted February 9, 2015 Author Posted February 9, 2015 the latest version is a total rewrite and in powershell but no longer writes to ad just to 1 csv file which can be viewed as a webpage. this is the last vbs version I have Option Explicit 'On Error Resume Next dim outputstring, computermodel, cpu, ram, hddcapacity, hddfree, serialno, macaddress, operatingsystem, csvoutput dim stcomputer, colitems, objItem, colcpu, colPhysicalMemory, objPhysicalMemory, intMemory, colDisks, objhdd dim colComputerSystem, colOperatingSystems, objOperatingSystem, colBIOS, objBIOS, colnicconfig, objnicconfig dim objwmiservice, hddtemp, weidata, colWSA, operatingsystemno, Lastuser, oreg, spath, svalue, strvalue, svaluename dim adoutputstring, adoRecordset, adoConnection, objRootDSE, objNetwork, objComputer, existing dim pcname, wshShell, strDirectory, strFile, objFSO, objFolder, objFile, objTextFile, myDateString dim colnet,objnet, linkspeed, objWMIService2 stcomputer = "." myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("winmgmts:\\" & stcomputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") Set colnicconfig = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") Set colWSA = objWMIservice.ExecQuery("Select * From Win32_WinSAT") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objWMIService2 = GetObject("winmgmts:\\" & stComputer & "\root\WMI") Set colnet = objWMIService2.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48) 'write file location pcname = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) strDirectory = "\\server\logs$\pcs\" strFile = pcname & ".csv" 'make-model For Each objItem In colItems computermodel= objItem.Manufacturer & " - " & objItem.Model 'wscript.echo computermodel Next ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'cpu info For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 ) & " MB" 'wscript.echo ram End If 'hdd capacity for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next 'windows version For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version 'wscript.echo operatingsystem Next 'serial no If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'mac address(s) If Not colnicconfig Is Nothing Then For Each objnicconfig in colnicconfig If macaddress <> "" Then macaddress = macaddress & " - " End If macaddress = macaddress & objnicconfig.MACAddress 'wscript.echo macaddress Next End If 'windows experience operatingsystemno = Left( operatingsystemno, 3 ) if operatingsystemno >5.5 then 'vista+ For Each objItem in colWSA 'weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" weidata = "Overall -" & objItem.WinSPRLevel & " - CPU - " & objItem.CPUScore & " - Memory - " & objItem.MemoryScore & " - Graphics - " & objItem.GraphicsScore & " - Gaming graphics - " & objItem.D3DScore & " - hdd - " & objItem.DiskScore next else 'xp- weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" end if 'last user if operatingsystemno >5.5 then 'vista+ Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & stcomputer & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & stcomputer End If End If else 'xp- Const HKEY_LOCAL_MACHINE = &H80000002 Set oreg=GetObject("winmgmts:\\" & stComputer & "\root\default:StdRegProv") spath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" svalue = "DefaultUserName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser=strvalue svalue = "DefaultDomainName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser = strvalue & "\" & lastuser end if 'Scans data for Net Speed For Each objnet in colnet 'Removes "slow/unused links" if objnet.NdisLinkSpeed/10 > 1000 then linkspeed= objnet.NdisLinkSpeed/10000 & " Mbps" & "-" & linkspeed '& "-" & objnet.NdisLinkSpeed/10000 & " Mbps" end if next 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," csvoutput = pcname & "," & computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & hddfree & "," & serialno & "," & operatingsystem & "," & macaddress & "," & weidata & "," & Lastuser & "," & linkspeed &"," & myDateString &"," ' wscript.echo outputstring ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) 'WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 2 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes result every time you run this VBScript objTextFile.WriteLine(csvoutput) objTextFile.Close If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) existing = objcomputer.Description if left (existing,1) = "#" and not right (existing,1) = "#" then outputstring = existing & " : " & outputstring & "#" if left (existing,1) = "#" and right (existing,1) = "#" then 'msgbox "data" wscript.quit end if if not objComputer.Description = outputstring then 'msgbox "diff" objComputer.Put "description", outputstring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If to change what goes to ad change line 154 (according to notepad ++) outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," to whatever variables you want/need
sted Posted February 9, 2015 Author Posted February 9, 2015 Infact there is a version past that but it dosent do ad but is simpler and does 1 csv file which can be viewed as a webpage but does generate blank lines in the csv sometimes 'gather pc info 'On Error Resume Next 'gather pc info v0 'J Stead March 2014 Option Explicit dim wmi,strComputerName,objWMIService,wshNetwork,colitems dim existing,newdata, filenamepath, outputArray, message, found, tobefilled, findstring, headers,objfs,objts dim strcontents, arrlines, i, myDateString set WMI = GetObject("winmgmts:\\.\root\cimv2") Set wshNetwork = WScript.CreateObject( "WScript.Network" ) strComputerName = wshNetwork.ComputerName myDateString = Date() 'mac address variables dim macadd, nictype, nad, nads set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true") 'computer name variables dim intMemory,objPhysicalMemory 'ram variables dim colPhysicalMemory,ram Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\CIMV2") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") 'pcinfo variables dim pcmake,pcmodel,objitem Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") 'cpu variables dim colcpu,cpu Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") 'os variables dim colOperatingSystems, operatingsystem, operatingsystemno, objOperatingSystem,splevel,installdate Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") 'serial no variables dim colbios,objbios,serialno Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") 'does stuff 'mac address(s) and nic type for each Nad in Nads if not isnull(Nad.MACAddress) then 'Wscript.Echo Nad.description, Nad.MACAddress macadd=macadd & " # " & Nad.MACAddress 'nictype=nictype & " # " & Nad.description end if next nictype=Replace(nictype,",","") 'wscript.echo macadd," ; " , nictype 'get pc name 'WScript.Echo "Computer Name: " & strComputerName 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 /1024 ) & " GB" 'wscript.echo ram End If 'make-model For Each objItem In colItems pcmake= objItem.Manufacturer pcmake= Replace(pcmake,",","") pcmodel = objItem.Model pcmodel = Replace(pcmodel,",","") 'wscript.echo pcmake & " # " & pcmodel Next 'cpu For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'os For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption splevel=objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version installdate=objOperatingSystem.InstallDate 'wscript.echo "os=" & operatingsystem &" sp= " & splevel & " osnumber " & operatingsystemno & " installed " & installdate Next 'serialno If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'hdd capacity dim objhdd,coldisks, hddcapacity, hddfree set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next newdata = macadd & "," & strComputerName & "," & pcmake & "," & pcmodel & "," & cpu & "," & ram & "," & hddcapacity & "," & hddfree & "," & serialno &"," & operatingsystem & "," & myDateString & "," Found="0" FindString=macadd filenamepath="\\server\inventory2$\inventorylog.csv" headers = "mac,name,make,model,cpu,ram size,hdd size,hdd free,serialno,windows version,date collected, dop,years warranty,warranty expires,location" tobefilled= "bought,years,expires,location" Set objFS = CreateObject("Scripting.FileSystemObject") If objFS.FileExists(filenamepath) Then 'wscript.echo "file exists" else 'wscript.echo "no file here" Set objFS = objFS.CreateTextFile(filenamepath) objFS.close Set objFS = CreateObject("Scripting.FileSystemObject") Set objFS = objFS.OpenTextFile(filenamepath, 2) objFS.write headers objFS.close end if Set objFS = CreateObject("Scripting.FileSystemObject") Set objTS = objFS.OpenTextFile(filenamepath, 1) strContents = objTS.ReadAll objTS.Close arrLines = Split(strContents, vbNewLine) Set objTS = objFS.OpenTextFile(filenamepath, 2) For i=0 To UBound(arrLines) If instr(arrLines(i),findstring) Then Found="1" outputArray = split(arrLines(i),",") objTS.writeline NewData & outputArray(11) & "," & outputArray(12) & "," & outputArray(13)& "," & outputArray(14) else objTS.Writeline arrLines(i) End If Next If Found="0" then objTS.Write newdata & tobefilled end if 'wscript.echo "the end?" 1
sted Posted February 9, 2015 Author Posted February 9, 2015 and for completeness the powershell version which allows 4 user defined columns at the end that don't get erased every time the script is run which I use for purchase date, warranty years, warranty ends and location again it has issues every now and again something causes it to wipe the csv file and not append anymore but its so random I havnt been able to track it down # system info ps v1 #locate output file & define default values $filepath="\\server\inventory2$\outputfile.csv" $dop="-" $warantyyears="-" $warantyend="-" $location = "-" $file="" $csvout="" $arrayloc="" $newline="" #import existing file if it exists if(test-path -path $filepath) { $fileexists="true" $file = Import-Csv $filepath } if(!(test-path -path $filepath)) { $fileexists="false" } # get mac address active cards (tested on multinics) $mac= Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"' | Select macAddress if ($mac.count) {$mac3=$mac.macaddress[0] + " : " + $mac.macaddress[1]} else {$mac3=$mac.macaddress} # get processor and pc name $procinfo = Get-WmiObject Win32_Processor $cpuname=$procinfo.Name $pcname=$procinfo.SystemName # get memory info/model/make $pcinfo = Get-WmiObject Win32_ComputerSystem $maker=$pcinfo.Manufacturer $model=$pcinfo.Model $ram=$pcinfo.TotalPhysicalMemory/1024/1024/1024 $ram = "{0:N1}" -f $ram #get serial no $serial=Get-WmiObject Win32_BIOS $serial2=$serial.SerialNumber #hdd size and free in gb rounded to nearest whole no $hdddata=Get-WmiObject Win32_LogicalDisk -Filter 'deviceid="c:"' $freespace=$hdddata.FreeSpace/1024/1024/1024 $freespace = "{0:N0}" -f $freespace $totalspace=$hdddata.size/1024/1024/1024 $totalspace = "{0:N0}" -f $totalspace # get windows version $os=Get-WmiObject Win32_OperatingSystem | select caption $os2=$os.caption #date-time $now= Get-Date $now2 = $now.date #create csv data if no existing file if ($fileexists -eq "false") { #echo "new file created" $csvout = New-Object psobject $csvout | add-member NoteProperty Macaddress $mac3 $csvout | add-member NoteProperty PCName $pcname $csvout | add-member NoteProperty Manufacturer $Maker $csvout | add-member NoteProperty "PC Model" $model $csvout | add-member NoteProperty Processor $CPUName $csvout | add-member NoteProperty Memory $ram $csvout | add-member NoteProperty "HDD Size" $totalspace $csvout | add-member NoteProperty "HDD Free" $freespace $csvout | add-member NoteProperty "Serial No" $serial2 $csvout | add-member NoteProperty "Windows Version" $os2 $csvout | add-member NoteProperty "Date Collected" $now2 $csvout | add-member NoteProperty "Date purchased" $dop $csvout | add-member NoteProperty "Warranty years" $warantyyears $csvout | add-member NoteProperty "Warranty Expiration" $warantyend $csvout | add-member NoteProperty "Location" $location $csvout | export-csv $filepath -notypeinformation #-Append } if($fileexists -eq "true") { $arrayloc=[array]::indexof($file.pcname, $pcname) if (!($arrayloc -eq -1)) { #echo "replacing data" #$file[$arrayloc] |Format-Table $file[$arrayloc].macaddress=$mac3 $file[$arrayloc].pcname= $pcname $file[$arrayloc].Manufacturer=$maker $file[$arrayloc]."pc model"=$model $file[$arrayloc].processor=$cpuname $file[$arrayloc].memory=$ram $file[$arrayloc]."hdd size" = $totalspace $file[$arrayloc]."hdd free" = $freespace $file[$arrayloc]."serial no" = $serial2 $file[$arrayloc]."Windows Version" = $os2 $file[$arrayloc]."Date Collected" = $now2 $file | export-csv $filepath -notypeinformation } if ($arrayloc -eq -1) { #echo "adding new line" $csvout = New-Object psobject $csvout | add-member NoteProperty Macaddress $mac3 $csvout | add-member NoteProperty PCName $pcname $csvout | add-member NoteProperty Manufacturer $Maker $csvout | add-member NoteProperty "PC Model" $model $csvout | add-member NoteProperty Processor $CPUName $csvout | add-member NoteProperty Memory $ram $csvout | add-member NoteProperty "HDD Size" $totalspace $csvout | add-member NoteProperty "HDD Free" $freespace $csvout | add-member NoteProperty "Serial No" $serial2 $csvout | add-member NoteProperty "Windows Version" $os2 $csvout | add-member NoteProperty "Date Collected" $now2 $csvout | add-member NoteProperty "Date purchased" $dop $csvout | add-member NoteProperty "Warranty years" $warantyyears $csvout | add-member NoteProperty "Warranty Expiration" $warantyend $csvout | add-member NoteProperty "Location" $location $csvout | export-csv $filepath -notypeinformation -Append } } 2
linkazoid Posted February 9, 2015 Posted February 9, 2015 Cheers @sted. I think the Powershell version may be the way to go for us. I need to be able to add the following in get-disk | ? model -match 'ssd' could you have a quick look to see if you could add this as I have very little idea where to start. regards, Michael
sted Posted February 11, 2015 Author Posted February 11, 2015 Cheers @sted. I think the Powershell version may be the way to go for us. I need to be able to add the following in get-disk | ? model -match 'ssd' could you have a quick look to see if you could add this as I have very little idea where to start. regards, Michael I have only run this as a test on its own but I see no reason why it cant just be plumbed into the above code note I don't have access to a pc with an ssd at the moment so it might require a bit of fettling and it assumes that any ssd with have a model name that says ssd (I cant vouch for that and I doubt say a surfaces msata drive shows as ssd even though it is basically) $disktype = Get-WmiObject win32_diskdrive if ($disktype.model -like '*ssd*') {$ssd='ssd'} else {$ssd='hdd'} $ssd you just need to add the top 2 lines near the top and add $ssd into the $csvout at the bottom but as said ive not tested it
internetuser Posted June 7, 2017 Posted June 7, 2017 Quick question, used the script for years, and works well. How ever is it possible to add the IP address to the description field ?
sted Posted June 7, 2017 Author Posted June 7, 2017 (edited) id imagine so not that ive tried it. what variation of the script are you using as ive got so many at this point including an abandoned powershell version lol ive just had a quick look and the code below will get you the ipv4 address you just need to dump strMsg to your output line (and tidy up the code so it works within the existing one strMsg = "" strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) If Not Instr(IPConfig.IPAddress(i), ":") > 0 Then strMsg = strMsg & IPConfig.IPAddress(i) & vbcrlf End If Next End If Next wscript.Echo strMsg Edited June 7, 2017 by sted
internetuser Posted June 7, 2017 Posted June 7, 2017 cheers will give it a go, I think I am using the last vbs one.
internetuser Posted June 7, 2017 Posted June 7, 2017 Got it working, sort of. Anyway to fix it from showing both IP addresses like this 101.100.11.137169.254.69.36, even if it just lists one IP address ? And it does a strange thing with the csv file and splits it over different rows now, and not all in one row.
blazedbud Posted January 29, 2019 Posted January 29, 2019 This script will give you pretty much everything you need from server / computers. Let me know if you need any additional lines adding #Get the server list $servers = Get-Content C:\PATH-TO-LIST-OF-COMPUTERS-OR-SERVERS\Serverlist.txt #Run the commands for each server in the list $infoColl = @() Foreach ($s in $servers) { $CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information $OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information #System Information $Domain = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $s $ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $s #GetC Server Details - Model, etc $System = Get-WmiObject -Query "SELECT * FROM Win32_SystemEnclosure" -Namespace "root\CIMV2" -ComputerName $s #Get server serial number #Hard Drive Information #Network Information $IPAddresses = Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $s | Where-Object -FilterScript {$_.IPEnabled} | Select-Object @{Name=’IPAddress’;Expression={[string]::join(“ - ”, ($_.IpAddress))}} $DNSEntries = Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $s | Where-Object -FilterScript {$_.IPEnabled} | Select-Object @{Name=’DNS’;Expression={[string]::join(“ - ”, ($_.DNSServerSearchOrder))}} $PersitentRouteIP = Get-WMIObject -Class Win32_IP4PersistedRouteTable -ComputerName $s | Select-Object @{Name=’IPAddress’;Expression={[string]::join(“ - ”, ($_.Destination))}}, ` @{Name=’NetMask’;Expression={[string]::join(“ - ”, ($_.mask))}}, ` @{Name=’DefaultGateway’;Expression={[string]::join(“ - ”, ($_.NextHop))}} $MACAddress = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $s | Where-Object -FilterScript {$_.IPEnabled} | Select-Object @{Name=’MAC’;Expression={[string]::join(“ - ”, ($_.MacAddress))}} #Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal. $OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2) $OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2) $PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) } Foreach ($CPU in $CPUInfo) { $infoObject = New-Object PSObject #The following add data to the infoObjects. Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName Add-Member -InputObject $infoObject -MemberType NoteProperty -name "Domain" -value $Domain.domain Add-Member -InputObject $infoObject -MemberType NoteProperty -name "SerialNumber" -value $System.SerialNumber Add-Member -InputObject $infoObject -MemberType NoteProperty -name "ServerManufacturer" -value $ComputerSystem.Manufacturer Add-Member -InputObject $infoObject -MemberType NoteProperty -name "ServerModel" -value $ComputerSystem.Model Add-Member -InputObject $infoObject -MemberType NoteProperty -name "IPAdresses" -value $IPAddresses Add-Member -InputObject $infoObject -MemberType NoteProperty -name "DNSEntries" -value $DNSEntries Add-Member -InputObject $infoObject -MemberType NoteProperty -name "PersitentRouteIP" -value $PersitentRouteIP Add-Member -InputObject $infoObject -MemberType NoteProperty -name "MACAddress" -value $MACAddress Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores Add-Member -inputObject $infoObject -memberType NoteProperty -name "Sockets" -value $CPU.SocketDesignation Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPUThreads" -value $CPU.NumberOfLogicalProcessors Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Name" -value $OSInfo.Caption Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Version" -value $OSInfo.Version Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalPhysical_Memory_GB" -value $PhysicalMemory $infoObject #Output to the screen for a visual feedback. $infoColl += $infoObject } } $infoColl | Export-Csv -path C:\PATH-TO-CSV-OUTPUT-FILE\ServerInventory_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation #Export the results in csv file.
Dianalv Posted April 18, 2019 Posted April 18, 2019 Had same issue but now also got it working, thanks
mdrabble Posted May 10, 2019 Posted May 10, 2019 and for completeness the powershell version which allows 4 user defined columns at the end that don't get erased every time the script is run which I use for purchase date, warranty years, warranty ends and location again it has issues every now and again something causes it to wipe the csv file and not append anymore but its so random I havnt been able to track it down # system info ps v1 #locate output file & define default values $filepath="\\server\inventory2$\outputfile.csv" $dop="-" $warantyyears="-" $warantyend="-" $location = "-" $file="" $csvout="" $arrayloc="" $newline="" #import existing file if it exists if(test-path -path $filepath) { $fileexists="true" $file = Import-Csv $filepath } if(!(test-path -path $filepath)) { $fileexists="false" } # get mac address active cards (tested on multinics) $mac= Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"' | Select macAddress if ($mac.count) {$mac3=$mac.macaddress[0] + " : " + $mac.macaddress[1]} else {$mac3=$mac.macaddress} # get processor and pc name $procinfo = Get-WmiObject Win32_Processor $cpuname=$procinfo.Name $pcname=$procinfo.SystemName # get memory info/model/make $pcinfo = Get-WmiObject Win32_ComputerSystem $maker=$pcinfo.Manufacturer $model=$pcinfo.Model $ram=$pcinfo.TotalPhysicalMemory/1024/1024/1024 $ram = "{0:N1}" -f $ram #get serial no $serial=Get-WmiObject Win32_BIOS $serial2=$serial.SerialNumber #hdd size and free in gb rounded to nearest whole no $hdddata=Get-WmiObject Win32_LogicalDisk -Filter 'deviceid="c:"' $freespace=$hdddata.FreeSpace/1024/1024/1024 $freespace = "{0:N0}" -f $freespace $totalspace=$hdddata.size/1024/1024/1024 $totalspace = "{0:N0}" -f $totalspace # get windows version $os=Get-WmiObject Win32_OperatingSystem | select caption $os2=$os.caption #date-time $now= Get-Date $now2 = $now.date #create csv data if no existing file if ($fileexists -eq "false") { #echo "new file created" $csvout = New-Object psobject $csvout | add-member NoteProperty Macaddress $mac3 $csvout | add-member NoteProperty PCName $pcname $csvout | add-member NoteProperty Manufacturer $Maker $csvout | add-member NoteProperty "PC Model" $model $csvout | add-member NoteProperty Processor $CPUName $csvout | add-member NoteProperty Memory $ram $csvout | add-member NoteProperty "HDD Size" $totalspace $csvout | add-member NoteProperty "HDD Free" $freespace $csvout | add-member NoteProperty "Serial No" $serial2 $csvout | add-member NoteProperty "Windows Version" $os2 $csvout | add-member NoteProperty "Date Collected" $now2 $csvout | add-member NoteProperty "Date purchased" $dop $csvout | add-member NoteProperty "Warranty years" $warantyyears $csvout | add-member NoteProperty "Warranty Expiration" $warantyend $csvout | add-member NoteProperty "Location" $location $csvout | export-csv $filepath -notypeinformation #-Append } if($fileexists -eq "true") { $arrayloc=[array]::indexof($file.pcname, $pcname) if (!($arrayloc -eq -1)) { #echo "replacing data" #$file[$arrayloc] |Format-Table $file[$arrayloc].macaddress=$mac3 $file[$arrayloc].pcname= $pcname $file[$arrayloc].Manufacturer=$maker $file[$arrayloc]."pc model"=$model $file[$arrayloc].processor=$cpuname $file[$arrayloc].memory=$ram $file[$arrayloc]."hdd size" = $totalspace $file[$arrayloc]."hdd free" = $freespace $file[$arrayloc]."serial no" = $serial2 $file[$arrayloc]."Windows Version" = $os2 $file[$arrayloc]."Date Collected" = $now2 $file | export-csv $filepath -notypeinformation } if ($arrayloc -eq -1) { #echo "adding new line" $csvout = New-Object psobject $csvout | add-member NoteProperty Macaddress $mac3 $csvout | add-member NoteProperty PCName $pcname $csvout | add-member NoteProperty Manufacturer $Maker $csvout | add-member NoteProperty "PC Model" $model $csvout | add-member NoteProperty Processor $CPUName $csvout | add-member NoteProperty Memory $ram $csvout | add-member NoteProperty "HDD Size" $totalspace $csvout | add-member NoteProperty "HDD Free" $freespace $csvout | add-member NoteProperty "Serial No" $serial2 $csvout | add-member NoteProperty "Windows Version" $os2 $csvout | add-member NoteProperty "Date Collected" $now2 $csvout | add-member NoteProperty "Date purchased" $dop $csvout | add-member NoteProperty "Warranty years" $warantyyears $csvout | add-member NoteProperty "Warranty Expiration" $warantyend $csvout | add-member NoteProperty "Location" $location $csvout | export-csv $filepath -notypeinformation -Append } } Taken a copy of the script and amended it so I can grab details and import into SnipeIT :-) 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now