Read Content from Text File VBS

DisplayName

Hi Guys this script requires you to manually enter computer name to pull up Inventory.

If I can have all the computer's name in a text file that will be great.

I tried something like

strComputer  = fso1.OpenTextFile("c:\Computers.txt",1) 

But doesn't seems to work any idea?

Dim strIP, strSubnet, strDescription, lnX, strcomputer, objwmiservice, colitems, objitems

strComputer  =  InputBox ("Enter the Computer name to get its Inventory:-")
lnX = 1

' ********************************************************************************************
'Section to change a filename using timestamps
strPath  =  "C:\"   
strMonth  =  DatePart("m", Now())
strDay  =  DatePart("d",Now())

if Len(strMonth) = 1 then
 strMonth  =  "0" & strMonth
else
 strMonth  =  strMonth
end if

if Len(strDay) = 1 then
 strDay  =  "0" & strDay
else
 strDay  =  strDay
end if

strFileName  =  DatePart("yyyy",Now()) & strMonth & strDay 
strFileName  =  Replace(strFileName,":","")
' ********************************************************************************************

'Variable Declarations
Const ForAppending  =  8

'Get CompName
Set objWMIService  =  GetObject("winmgmts:" & "{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")

' ********************************************************************************************
'Get Operation System & Processor Information
' ********************************************************************************************
Set colItems  =  objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
     CompName  =  objItem.SystemName
Next

Set objFSO  =  CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(strPath & CompName & "_" & "_Inventory.txt") then
 WScript.Quit
end if

'Set the file location 
Set objFSO  =  CreateObject("Scripting.FileSystemObject")
Set objTextFile  =  objFSO.OpenTextFile(strPath & CompName & "_" & "Inventory.txt", ForAppending, True)

' ********************************************************************************************
'Print HEADER
' ********************************************************************************************
objTextFile.Write "********************************************************************************************" & VBCRLF & VBCRLF
objTextFile.Write "                     COMPUTER INVENTORY                         " & VBCRLF
objTextFile.Write "                     DATE:  " &    FormatDateTime(Now(),1)   & "                   " & VBCRLF
objTextFile.Write "                     TIME:  " &    FormatDateTime(Now(),3)   & "                   " & VBCRLF & VBCRLF
objTextFile.Write "******************************************************************************************** " & VBCRLF & VBCRLF 

' ********************************************************************************************
'Get Processor Information
' ********************************************************************************************
objTextFile.Write "COMPUTER" & VBCRLF 
Set colItems  =  objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
    If lnX = 1 Then
     objTextFile.Write "          COMPUTER NAME: " &  objItem.SystemName & VBCRLF
     objTextFile.Write "          PROCESSOR: " &  objItem.Name & vbCrLf
     lnX = lnX + 1
    End If
Next

' ********************************************************************************************
'Get Computer Manufacturer and RAM details
' ********************************************************************************************
Set colSystems  =  objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objSystems In colSystems
  objTextFile.WriteLine "          MANUFACTURER: " & objSystems.Manufacturer
  objTextFile.WriteLine "          MODEL: " & objSystems.Model
  objTextFile.WriteLine "          DOMAIN: " & objsystems.Domain
  objTextFile.Write "          RAM: " & Round (objSystems.TotalPhysicalMemory / 1048576, 0) & " MB "& VBCRLF 
Next

' ********************************************************************************************
' Get the Serial number/ Service Tag of the system
' ********************************************************************************************
Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") 
For Each objSMBIOS in colSMBIOS 
    objTextFile.Write "          SERVICE TAG: " & objSMBIOS.SerialNumber & VBCRLF
Next 

' ********************************************************************************************
'Get BIOS Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "BIOS INFO" & vbCrLf
Set colBIOS  =  objWMIService.ExecQuery("Select * from Win32_BIOS")
For each objItem in colBIOS
    objTextFile.WriteLine "          BIOS MANUFACTURER: " & objItem.Manufacturer
    objTextFile.WriteLine "          BIOS VERSION: " & objItem.Name
Next

' ********************************************************************************************
'Get OS Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "OS INFO" & vbCrLf
Set colSettings  =  objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
    objTextFile.Write "          OPERATING SYSTEM: " & objOperatingSystem.Caption & " {Enter the product key}" & VBCRLF
    objTextFile.Write "          SERVICE PACK: " & objOperatingSystem.Caption & " Service Pack "& objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion & VBCRLF 
Next



' ********************************************************************************************
'Get Logical Disk Size and Partition Information
' ********************************************************************************************
objTextFile.Write VBCRLF & "MEMORY" & VBCRLF 
Set colDisks  =  objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType  =  3")
For Each objDisk in colDisks
    intFreeSpace  =  objDisk.FreeSpace
    intTotalSpace  =  objDisk.Size
    pctFreeSpace  =  intFreeSpace / intTotalSpace
    objTextFile.Write objDisk.Name & "\ (" & objDisk.FileSystem & ") " &  Round((objDisk.Size/1000000000),4) & " GB ("& Round((intFreeSpace/1000000000)*1.024,4) & " GB Free Space)" & VBCRLF
Next

' ********************************************************************************************
'Get NETWORK ADAPTERS information
' ********************************************************************************************
objTextFile.Write VBCRLF & "NETWORK" & VBCRLF 
Set colNicConfigs  =  objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled  =  True")
For Each objNicConfig In colNicConfigs
    strDescription = objNicConfig.Caption
    strMACAddress = objNicConfig.MACAddress
    strDHCP = objNicConfig.DHCPEnabled

    For Each strIPAddress In objNicConfig.IPAddress
        strIP = strIPAddress        'Assign IP Address to variable
        For Each strIPSubnet In objNicConfig.IPSubnet
            strSubnet  =  strIPSubnet       'Assign Subnet to variable
        Next
        objTextFile.Write "          NETWORK ADAPTER: " & strDescription & VBCRLF
        objTextFile.Write "          IP ADDRESS: " & strIP & VBCRLF
        objTextFile.Write "          MAC ADDRESS: " & strMACAddress & vbCrLf
        objTextFile.Write "          DHCP ENABLED: " & strDHCP & vbCrLf & vbCrLf 
    Next

Next
Set colNicConfigs  = NOTHING

' ********************************************************************************************
'Get GRAPHICS ADAPTERS information
' ********************************************************************************************
objTextFile.Write VBCRLF & "GRAPHICS CARD" & VBCRLF 
Set colGraphics  =  objWMIService.ExecQuery ("Select * from Win32_DisplayControllerConfiguration")
For Each objGraphics in colGraphics
    objTextFile.WriteLine "          GRAPHICS CARD: " & objGraphics.Name & VBCRLF 
Next

' ********************************************************************************************
' Get the list of Installed software
' ********************************************************************************************
objTextFile.Write VBCRLF & "SOFTWARE INSTALLED" & VBCRLF 
Set colSoftware  =  objWMIService.ExecQuery("Select * from Win32_Product")
For Each objSoftware in colSoftware
    objTextFile.WriteLine objSoftware.Description 
Next

'Close text file after writing logs
objTextFile.Write VbCrLf
objTextFile.Close

'Clean Up
WScript.Echo "Inventory Complete "
Ekkehard.Horner

The .OpenTextFile() call in your

strComputer = fso1.OpenTextFile("c:\Computers.txt",1)

just opens the file, but does not read the file's content that should be assigned to strComputer. So use

strComputer = fso1.OpenTextFile("c:\Computers.txt").ReadLine()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get VBS to read from text file?

From Dev

read data from text file and filter content

From Dev

Why does VBS not read this text file correctly?

From Dev

Is it possible to read content from a local text file using Javascript?

From Dev

Read content from text file formed in Windows in Linux bash

From Dev

Read from a text file

From Dev

remove nul characters from text file using vbs

From Dev

read text file content and insert it into a mysql database

From Dev

Read text file content into matrix based on condition

From Dev

Read a variable from a text file

From Dev

Read json from text file

From Dev

How to read a text file content and write to another text file after formatting the text file content using Java?

From Dev

How to read content from plain text remote file with objective-c

From Dev

Reading file content from uploaded text file

From Dev

Get file path from system directory using Flutter web (chrome) to read file content Eg: CSV or Text file

From Dev

Read content of text file and use it to change text of a TextBlock

From Dev

read the content of file by getting it from dll

From Dev

Simple Snippet to read and show content from file

From Dev

read the content of file by getting it from dll

From Dev

Simple Snippet to read and show content from file

From Dev

Download file from webserver and read content on android

From Dev

Read content of .txt file from URL

From Dev

Batch file to read lines from text file

From Dev

Vbs Make a text file with text written in it

From Dev

Vbs Make a text file with text written in it

From Dev

Replace text in text file using VBS

From Dev

VBS Save File From Link

From Dev

VBS Save File From Link

From Dev

Read line per line a txt file with VBS

Related Related

  1. 1

    How to get VBS to read from text file?

  2. 2

    read data from text file and filter content

  3. 3

    Why does VBS not read this text file correctly?

  4. 4

    Is it possible to read content from a local text file using Javascript?

  5. 5

    Read content from text file formed in Windows in Linux bash

  6. 6

    Read from a text file

  7. 7

    remove nul characters from text file using vbs

  8. 8

    read text file content and insert it into a mysql database

  9. 9

    Read text file content into matrix based on condition

  10. 10

    Read a variable from a text file

  11. 11

    Read json from text file

  12. 12

    How to read a text file content and write to another text file after formatting the text file content using Java?

  13. 13

    How to read content from plain text remote file with objective-c

  14. 14

    Reading file content from uploaded text file

  15. 15

    Get file path from system directory using Flutter web (chrome) to read file content Eg: CSV or Text file

  16. 16

    Read content of text file and use it to change text of a TextBlock

  17. 17

    read the content of file by getting it from dll

  18. 18

    Simple Snippet to read and show content from file

  19. 19

    read the content of file by getting it from dll

  20. 20

    Simple Snippet to read and show content from file

  21. 21

    Download file from webserver and read content on android

  22. 22

    Read content of .txt file from URL

  23. 23

    Batch file to read lines from text file

  24. 24

    Vbs Make a text file with text written in it

  25. 25

    Vbs Make a text file with text written in it

  26. 26

    Replace text in text file using VBS

  27. 27

    VBS Save File From Link

  28. 28

    VBS Save File From Link

  29. 29

    Read line per line a txt file with VBS

HotTag

Archive