About us

IIS covers the IT solutions to the issues come across now and then in a company IT infrastructure including Operating system, Softwares, Scriptings, securities and reviews.

Saturday, 25 October 2014

Save computer inventory in text file - Save your precious time !!

In the early days of my joining in IT infrastructure team I encountered a handful of instances where I had to note down serial number, Model number, Operating system, Physical Memory, HDD manually and many other things which used to be so time consuming.

As a result I created one script so that I could have all that information in one text file and I could save it on my system and share with everybody. Here below is one of my script.

****Start

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
ff=wshNetwork.ComputerName
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
Model = objItem.Model
RAM = Int(objItem.TotalPhysicalMemory /(100000000))
timenow = Now
Next
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each os in oss
OSystem = os.Caption
Next
For each objBIOS in colBIOS
    Manufacturer = objBIOS.Manufacturer
    Serial= objBIOS.SerialNumber
Next
Set colChassis = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure",,16)
For Each objChassis in colChassis
  For Each objItem in objChassis.ChassisTypes
    Select Case objItem
    Case 1 strChassis = "Maybe Virtual Machine"
    Case 2 strChassis = "??"
    Case 3 strChassis = "Desktop"
    Case 4 strChassis = "Thin Desktop"
    Case 5 strChassis = "Pizza Box"
    Case 6 strChassis = "Mini Tower"
    Case 7 strChassis = "Full Tower"
    Case 8 strChassis = "Portable"
    Case 9 strChassis = "Laptop"
    Case 10 strChassis = "Notebook"
    Case 11 strChassis = "Hand Held"
    Case 12 strChassis = "Docking Station"
    Case 13 strChassis = "All in One"
    Case 14 strChassis = "Sub Notebook"
    Case 15 strChassis = "Space-Saving"
    Case 16 strChassis = "Lunch Box"
    Case 17 strChassis = "Main System Chassis"
    Case 18 strChassis = "Lunch Box"
    Case 19 strChassis = "SubChassis"
    Case 20 strChassis = "Bus Expansion Chassis"
    Case 21 strChassis = "Peripheral Chassis"
    Case 22 strChassis = "Storage Chassis"
    Case 23 strChassis = "Rack Mount Unit"
    Case 24 strChassis = "Sealed-Case PC"
    End Select
  Next
Next
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")

For Each Nic in NIC1

if Nic.IPEnabled then

StrIP = Nic.IPAddress(i)
MAC = Nic.MACAddress
end If
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
    CPU = objItem.Name
Next
Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office%'")

    If colSoft.Count = 0 Then
MS = "NO OFFFICE INSTALLED"
    else
       For Each objItem In colSoft
          MS = objitem.caption
          exit for
       Next
    End If
Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Sony Sound%'")

    If colSoft.Count = 0 Then
Sony = "NOSonySoundForge"
    else
       For Each objItem In colSoft
          Sony = objitem.caption
          exit for
       Next
    End If
'Visio

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office Visio%'")

    If colSoft.Count = 0 Then
Visio = "NOVisio"
    else
       For Each objItem In colSoft
          Visio = objitem.caption
          exit for
       Next
    End If
'OneNote

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office OneNote%'")

    If colSoft.Count = 0 Then
OneNote = "NOOneNote"
    else
       For Each objItem In colSoft
          OneNote = objitem.caption
          exit for
       Next
    End If

'Project

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office Project%'")

    If colSoft.Count = 0 Then
Project = "NOProject"
    else
       For Each objItem In colSoft
          Project = objitem.caption
          exit for
       Next
    End If
'Visual Studio

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Visual Studio%'")

    If colSoft.Count = 0 Then
VS = "NOVS"
    else
       For Each objItem In colSoft
          VS = objitem.caption
          exit for
       Next
    End If
'FrontPage

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office FrontPage%'")

    If colSoft.Count = 0 Then
FrontPage = "NOFrontPage"
    else
       For Each objItem In colSoft
          FrontPage = objitem.caption
          exit for
       Next
    End If

'Photoshop

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Adobe Photoshop%'")

    If colSoft.Count = 0 Then
Photoshop = "NOPhotoshop"
    else
       For Each objItem In colSoft
          Photoshop = objitem.caption
          exit for
       Next
    End If

'CC

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Adobe Creative Cloud%'")

    If colSoft.Count = 0 Then
CC = "NOCC"
    else
       For Each objItem In colSoft
          CC = objitem.caption
          exit for
       Next
    End If

'Illustrator

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like '%Illustrator%'")

    If colSoft.Count = 0 Then
Illustrator = "NOIllustrator"
    else
       For Each objItem In colSoft
          Illustrator = objitem.caption
          exit for
       Next
    End If

'Flash

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like '%DreamWeaver%'")

    If colSoft.Count = 0 Then
Flash = "NOFlash"
    else
       For Each objItem In colSoft
          Flash = objitem.caption
          exit for
       Next
    End If

'Aftereffects

Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like '%Aftereffects%'")

    If colSoft.Count = 0 Then
Aftereffects = "NOAftereffects"
    else
       For Each objItem In colSoft
          Aftereffects = objitem.caption
          exit for
       Next
    End If
Set colItems = objWMIService.ExecQuery(_
"Select * from Win32_DiskDrive")
For Each objItem in colItems
HDD = Int(objItem.Size /(1000000000))
Next
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists("C:\Inv") Then
Set newfolder = fso.CreateFolder("C:\Inv")
End If
Set oFile = fso.OpenTextFile("C:\inv\" & ff &".txt",2,True)

oFile.Writeline wshNetwork.UserName &Space(1)& strChassis &Space(1)& Replace(Manufacturer," ","") &Space(1)& _
Replace(Model," ","") &Space(1)& Serial &Space(1)& wshNetwork.ComputerName _
&Space(1)&"N/A "&Replace(CPU," ","") &Space(1)& RAM &Space(1)& HDD &Space(1)& StrIP &Space(1)&MAC &Space(1)& _
Replace(OSystem," ","") &Space(1)& Replace(MS," ","") &Space(1)& Replace(Sony," ","")&Space(1)& Replace(Visio," ","") _
&Space(1)& Replace(OneNote," ","")&Space(1)& Replace(Project," ","")&Space(1)& Replace(VS," ","")&Space(1)& Replace(FrontPage," ","") _
&Space(1)& Replace(Photoshop," ","")&Space(1)& Replace(CC," ","")&Space(1)& Replace(Illustrator," ","") _
&Space(1)& Replace(Flash," ","")&Space(1)& Replace(DreamWeaver," ","") _
&Space(1)& Replace(Aftereffects," ","")&Space(1)& Replace((Now)," ","")
oFile.Close

sDestServer = "PCNOD513062"
Const OverwriteExisting = True

Sharepath = "\\" &sDestServer& "\Files\"
CopyFromPath = "C:\inv\" & ff &".txt"
FSO.CopyFile CopyFromPath,Sharepath,OverwriteExisting


***End
Regards, Baij

No comments:

Post a Comment