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,226 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

17 Experts available now in Live!

Get 1:1 Help Now