Solved

Create a VBS script to run on all network server

Posted on 2011-03-24
3
440 Views
Last Modified: 2012-06-21
I need to create a VB Script that will return the services running on a number of server and record this in a Text file (I need to find which services are running as domain\admin and domain\administrator)

I have part of the script, I just need to be able to run the script once, gather the info from all servers and record to a text file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("output.txt", True)

Set objService = GetObject("winmgmts:")
Set objCol = objService.ExecQuery("SELECT * FROM Win32_Service")
 For Each obj In objCol
      objFile.WriteLine & " ( " & obj.StartName & " )" & vbCrLf
 Next
WScript.Echo S
0
Comment
Question by:ronnie_urbanit
3 Comments
 
LVL 4

Expert Comment

by:MaximumIQ
Comment Utility
Your script looks fine. Only two things I see are both on this line

objFile.WriteLine & " ( " & obj.StartName & " )" & vbCrLf

1. you have an extra & after Writeline
2. Use obj.Name to give you a list of name (Some are abbreviated, not sure why)

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
Comment Utility
Hi, try this.

Regards,

Rob.
strOutput = "output.csv"
strComputers = "computers.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutput, True)

Set objInput = objFSO.OpenTextFile(strComputers, 1, False)
While Not objInput.AtEndOfStream
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
	Set objCol = objService.ExecQuery("SELECT * FROM Win32_Service")
	For Each obj In objCol
		objFile.WriteLine """" & obj.DisplayName & """,""" & obj.StartName & """"
	Next
Wend
objFile.Close
objInput.Close

WScript.Echo "Done. Please see " & strOutput

Open in new window

0
 
LVL 1

Author Closing Comment

by:ronnie_urbanit
Comment Utility
Script worked corrctly
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

6 Experts available now in Live!

Get 1:1 Help Now