Solved

vbs script to read registry values on remote computers and write the results in a csv or txt file

Posted on 2014-02-18
4
4,631 Views
Last Modified: 2014-02-18
I like this script below but instead of having to type the machine name one at a time with strComputer = InputBox("Enter the Name of the Remote PC: ")
I would like to just put all of my servers in a txt file and have it run this script against all servers in the list



' Set the constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8

' Create FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\temp\environment_variables.txt", ForAppending, True)


strComputer = InputBox("Enter the Name of the Remote PC: ")
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

objTextFile.WriteLine("PC Name: " & strComputer)
 
strKeyPath = "Software\SYMANTEC\Symantec Endpoint Protection\SMC"
strValueName = "ProductVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'Wscript.Echo "Current ProducVersion Value: " & strValue
objTextFile.WriteLine("Current ProductVersion Value: " & strValue)
 
 


objTextFile.WriteLine(vbCrLf)

objTextFile.Close
0
Comment
Question by:scriptz
  • 3
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 39868868
A simple loop should do the trick...

' Set the constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8

' Create FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("c:\temp\environment_variables.txt", ForAppending, True)

arrComputers = Split(objFSO.OpenTextFile("c:\temp\myComputers.txt").ReadAll, vbNewLine)

for each strComputer in arrComputers
  wscript.echo "Examining " & strComputer
  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  objFile.WriteLine "PC Name: " & strComputer
 
  strKeyPath = "Software\SYMANTEC\Symantec Endpoint Protection\SMC"
  strValueName = "ProductVersion"
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  'Wscript.Echo "Current ProducVersion Value: " & strValue
  objFile.WriteLine("Current ProductVersion Value: " & strValue)
  objFile.WriteLine(vbCrLf)
next 

objFile.Close

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39868876
Your source text file should contain a single computer name on each line of the file:

computer1
computer2
[etc]
0
 

Author Closing Comment

by:scriptz
ID: 39869037
This is exactly what I was looking for. Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39869121
Happy to help - thanks for the grade! :^)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

696 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