Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Self Contained List

Status
Not open for further replies.

Keyster86

IS-IT--Management
Jul 23, 2008
50
US
So, thinking out loud here. I want to know if there is a way to contain a list within a script running.

For example, I have a script that changes an admin password on all systems in my OU based on a list of computer names. The VBScript changes the password on each machine grabing the machine name(s) from a seperate text file called "whatever_you_want_to_call_it.txt".

What if there is a way to place a list inside the vbscript itself and then have the vbscript read itself; therefore, eleviating the need for a second file (the "whatever_you_want_to_call_it.txt").

Just a thought and curious what your thoughts might be. I plan to engineer a way to do this easily in the days to come - if it is possible.

Any thoughts/suggestions? :D

V/r,

SPC Key
United States Army
 
A script that reads AD computer list directly might be another answer.

V/r,

SPC Key
United States Army
 
I think you answered yourself, you could also use an array of server names.
 
Here would be my way of querying AD for computer names...What is your way?

Code:
OPTION EXPLICIT

DIM objOU, objComputer, objRootDSE, objLastLogon
DIM strContainer, strDNSDomain
DIM intLastLogonTime, intGuyTime

strContainer = "OU=COMPUTERS,"

SET objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

strContainer = strContainer & strDNSDomain
SET objOU =GetObject("LDAP://" & strContainer)

FOR EACH objComputer IN objOU
	IF LEFT(objComputer.sAMAccountName,15) = "!KBSC YONG Mana" THEN
	ELSE
		Wscript.Echo LEFT(objComputer.sAMAccountName,15)
	END IF
NEXT

WScript.echo "Done!"

SET objOU = NOTHING 
SET objComputer = NOTHING 
SET objRootDSE = NOTHING
SET objLastLogon = NOTHING
WScript.Quit

V/r,

SPC Key
United States Army
 
I'm with ettienne on this one... I think you answered your own question...

You have 2 choices.
1) Use an array:
Code:
 Dim aServers(2), sServer
aServers(0) = "Server1"
aServers(1) = "Server2"
aServers(2) = "Server3"

For Each sServer in aServers
    WScript.Echo sServer
Next

2) Query your list from a known good source, like AD. (I happen to pull data from the SQL DB of our monitoring system because it tends to be more accurate...)

Here's my take on your ADSI-based query:
Code:
Option Explicit
Dim oDSE, sDNC, cComputers, oComputer

[green]' Bind to AD... Future 'gets' will not re-bind (efficient)[/green]
Set oDSE = GetObject("LDAP://rootDSE")
sDNC = oDSE.Get("defaultNamingContext")

Const sContainer = "CN=Computers,"
Set cComputers = GetObject("LDAP://" & sContainer & sDNC)
cComputers.Filter = Array("Computer")

For Each oComputer In cComputers
	[green]' Name returned as <server$>... Strip $[/green]
	WScript.Echo Replace(oComputer.sAMAccountName, "$", "")
Next

You can also look at using ADODB, but that may be too involved for this small of a task...


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Good pointa.

You are both right, I could use an array to fill in the computer names (a self contained list); however, I think option two would be more efficient as it will require less typing.

Thanks for the input guys...really appericate it.

V/r,

SPC Key
United States Army
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top