Solved

Rocket Science for VBScript

Posted on 2009-05-14
10
384 Views
Last Modified: 2012-05-07
I'm going to condense this question as best as possible and try to eliminate as much fluff as possible so it's better understood as to what I'm needing, I'm needing help with a script that will do this:

Background info:  I have a Service Accounts OU, that has nothing but Service Accounts in them. In the Service Accounts Parent OU, I have 8 Sub OU's underneath it, within these Sub OU's are all of the Service Accounts.

Script:

1.)  Go out and list all Service Accounts in Service Accounts OU and it's 8 Sub OU's.

Next....

and this is a doosie....

2.)  Because these Service Accounts are required to run programs on some of the DC's around 30 total, they will not show the true IP addresses of where these Service Accounts originate from.  I'd like to find out the host IP address of these Service Accounts without having to go through the Auth Logs manually of each DC.  That of course would mean that the Script would have to go out to the Log Server and Scan through the Authentication logs of each DC to find the Service Accounts and associate the Host IP address of them.

NOTE:  I've attached a screen shot to hopefully offer some additional in-sight.
ServiceAccounts.JPG
0
Comment
Question by:itsmevic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 9

Accepted Solution

by:
gregcmcse earned 300 total points
ID: 24389245
You lost me at the end, and you're really asking two questions, but let me take your first one first.
See below for a code snippet to dump all accounts in a domain.  Instead of using the first two lines, put in strDN = "OU=Service Accounts,DC=mydomain,DC=com"
(replace mydomain.com and "Service Accounts" as appropriate).
For the second part of your question, are you asking how you can tell the original source computer that the service account logged in to?

Set oDSE = GetObject("LDAP://rootDSE")
strDN = oDSE.Get("defaultNamingContext")
 
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Open "DS Query"
Set oComm = CreateObject("ADODB.Command")
oComm.ActiveConnection = oConn
OComm.Properties("Page Size") = 1000
oComm.CommandText = "<LDAP://" & strDN & ">;(&(objectclass=user)(objectcategory=person));ADsPath;subtree"
Set oRS = oComm.Execute
 
Do While Not oRS.EOF
	UserDN = oRS.Fields("ADsPath")
	WScript.Echo UserDN
	oRs.MoveNext
Loop
Set oRs = Nothing

Open in new window

0
 

Author Comment

by:itsmevic
ID: 24389931
Ques:  For the second part of your question, are you asking how you can tell the original source computer  
            that the service account logged in to?

Ans:   That is correct.

0
 

Author Comment

by:itsmevic
ID: 24390133
the script worked great, give's a reading per click on screen.  Is there way to dump this into say a text file or .csv?
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 17

Assisted Solution

by:Jared Luker
Jared Luker earned 200 total points
ID: 24390187
run it with cscript and redirect the output to a text file...

cscript script.vbs >> log.txt
0
 

Author Comment

by:itsmevic
ID: 24390431
Ug getting errors....
Dim objShell,objFile,objFso,strTmp,strCommand,strInput
 
Set objShell = CScript.CreateObject("CScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")
strTmp = "C:\Scripts\ServiceAcctsListing.txt"
Set oDSE = GetObject("LDAP://rootDSE")
strDN = "OU=ServiceAccounts,DC=test,DC=test,DC=COM"
 
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Open "DS Query"
Set oComm = CreateObject("ADODB.Command")
oComm.ActiveConnection = oConn
OComm.Properties("Page Size") = 1000
oComm.CommandText = "<LDAP://" & strDN & ">;(&(objectclass=user)(objectcategory=person));ADsPath;subtree"
Set oRS = oComm.Execute
 
Do While Not oRS.EOF
        UserDN = oRS.Fields("ADsPath")
        CScript.Echo UserDN
        oRs.MoveNext
Loop
Set oRs = Nothing

Open in new window

0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24402423
Line 7: "OU=ServiceAccounts,DC=test,DC=test,DC=COM"...

should this be "OU=ServiceAccounts,DC=test,DC=COM"

If you're actually specifying the base of the search (which strDN is doing), you also don't need line 6 - it's now redundant.
0
 

Author Comment

by:itsmevic
ID: 24422850
Hi Blunt that worked out nicely and I now have a dialog that pops up showing me the user name, I click ok and it cycles through to the next user, this is great, however I'd have to click it a lot to make it through the entire thing.  Is it possible, for the output to be text, this might make reading it a little simpler.
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 24423033
run the script with cscript from the command line instead of wscript

Open up a command windows and type:

cscript ScriptName.vbs

That will make the command line processor execute the script and any echos will be written to the screen instead of making a popup box (unless a msgbox is used)

0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24423055
Call it from the command prompt using cscript and output it to a text file (as stated by Jared earlier):

cscript myscript > results.txt
0
 

Author Closing Comment

by:itsmevic
ID: 31583054
THANKS appreciated all the input on this.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

733 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