Solved

Need to Run VBScript to Read list of servers from a text file

Posted on 2011-03-04
4
675 Views
Last Modified: 2012-05-11
I need to execute the following VBscript on a list of servers that are listed on a text file. Please advise.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo "OS Name: " & objOperatingSystem.Name
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
Wscript.Echo "Windows Directory: " & _
objOperatingSystem.WindowsDirectory
Wscript.Echo "Locale: " & objOperatingSystem.Locale
Wscript.Echo "Available Physical Memory: " & _
objOperatingSystem.FreePhysicalMemory
Wscript.Echo "Total Virtual Memory: " & _
objOperatingSystem.TotalVirtualMemorySize
Wscript.Echo "Available Virtual Memory: " & _
objOperatingSystem.FreeVirtualMemory
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
Wscript.Echo "System Name: " & objComputer.Name
Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
Wscript.Echo "System Model: " & objComputer.Model
Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
Wscript.Echo "Total Physical Memory: " & _
objComputer.TotalPhysicalMemory
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
Wscript.Echo "System Type: " & objProcessor.Architecture
Wscript.Echo "Processor: " & objProcessor.Description
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For Each objBIOS in colSettings
Wscript.Echo "BIOS Version: " & objBIOS.Version
Next
0
Comment
Question by:mmoya
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Tasmant
ID: 35037340

Set oFSO = CreateObject("scripting.filesystemobject")
Const ForReading = 1

Path = "c:\servers.txt"

Set ofile = ofso.OpenTextFile(Path,ForReading)

Do Until ofile.AtEndOfStream
	strComputer = ofile.ReadLine
	
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_OperatingSystem")
	
	For Each objOperatingSystem in colSettings
		Wscript.Echo "OS Name: " & objOperatingSystem.Name
		Wscript.Echo "Version: " & objOperatingSystem.Version
		Wscript.Echo "Service Pack: " & _
		objOperatingSystem.ServicePackMajorVersion _
		& "." & objOperatingSystem.ServicePackMinorVersion
		Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
		Wscript.Echo "Windows Directory: " & _
		objOperatingSystem.WindowsDirectory
		Wscript.Echo "Locale: " & objOperatingSystem.Locale
		Wscript.Echo "Available Physical Memory: " & _
		objOperatingSystem.FreePhysicalMemory
		Wscript.Echo "Total Virtual Memory: " & _
		objOperatingSystem.TotalVirtualMemorySize
		Wscript.Echo "Available Virtual Memory: " & _
		objOperatingSystem.FreeVirtualMemory
		Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_ComputerSystem")
	
	For Each objComputer in colSettings
		Wscript.Echo "System Name: " & objComputer.Name
		Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
		Wscript.Echo "System Model: " & objComputer.Model
		Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
		Wscript.Echo "Total Physical Memory: " & _
		objComputer.TotalPhysicalMemory
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_Processor")
	
	For Each objProcessor in colSettings
		Wscript.Echo "System Type: " & objProcessor.Architecture
		Wscript.Echo "Processor: " & objProcessor.Description
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_BIOS")
	
	For Each objBIOS in colSettings
		Wscript.Echo "BIOS Version: " & objBIOS.Version
	Next
Loop
ofile.Close

Open in new window

0
 

Author Comment

by:mmoya
ID: 35039977
Last question..what about this one? I need to read list of servers from a file and execute this against it.. Thank you.

Option Explicit 'all variables must be defined

Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."

'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{5B478A76-6432-4296-9668-50FF58CA343B}"

'********************************

' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")

'**************************
UninstallString = "MsiExec.exe /X" & ProductCode & " /qn" & " /norestart"

Const HKEY_LOCAL_MACHINE = &H80000002

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
 
 IF subkey = ProductCode Then
 oShell.Run UninstallString, 1, True
 End If

Next

Set oShell = Nothing
Set oReg = Nothing
'************* End Code ************
0
 

Author Comment

by:mmoya
ID: 35040014
Please disregard the previous one. This is a more efficient way to uninstall an app. Use this instead..Thanks a bunch!

strApplicationName = "MSN Messenger 6.1"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("Select * From Win32_Product Where Name = '" & strApplicationName & "'")

For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
0
 
LVL 11

Accepted Solution

by:
Tasmant earned 500 total points
ID: 35055498

Set oFSO = CreateObject("scripting.filesystemobject")
Const ForReading = 1

strApplicationName = "MSN Messenger 6.1"
strPath = "c:\servers.txt"

Set ofile = ofso.OpenTextFile(strPath,ForReading)

Do Until ofile.AtEndOfStream
	strComputer = ofile.ReadLine
	
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colSoftware = objWMIService.ExecQuery("Select * From Win32_Product Where Name = '" & strApplicationName & "'")
	
	For Each objSoftware in colSoftware
		objSoftware.Uninstall()
	Next
Loop

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now