vbscript - get user and computer details from AD

Does anyone have a vbscript that will query both the local computer and AD (as appropriate) to return the information below.  I'm struggling about with forming the required LDAP calls.
current (logged on) UserName
Computer (Host) Name
IP Address
OS version & service packs (if applied)
Location of computer (from AD)

I'd also like to amend the script so as to query the whole domain and return most of the above information in a csv file but with last logged in user & date/time  instead of current Username.

Domain Name = MyDomain.Local
Domain Controller = MyDC
Script needs to run on both XP Pro and Windows 7 Pro
The domain is Server 2003
LVL 1
cmdownAsked:
Who is Participating?
 
x-menIT super heroCommented:
sorry for the delay:

here's your first request:

the script accepts 1 argument (the computer name)

c:\>cscript ee.vbs MyComputer

ee.vbs
0
 
Mike KlineCommented:
An LDAP query alone won't be able to remotely get you info from the local boxes.  you can use it to pull info from AD though using a tool like adfind

http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -default -f "objectcategory=computer" name operatingsystem operatingsystemservicepack -csv > c:\machinesfromAD.csv

Guys from the VBScript zone may help with the other info but things like last logged on user have to be pulled from event logs.

Thanks

Mike
0
 
x-menIT super heroCommented:
The plan is:

Search through AD for the “computer” object types and retrieve the Computer Name, OS version, service Pack and Location.
Go through each of these computers to check for the “Logon User Name” registry entry to query AD (again) for the users “Last logon Time” property.
And save it in a csv format.

Just give me some time, and I’ll get you the script.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
yehudahaCommented:
can you give example to exectly what you want
0
 
x-menIT super heroCommented:
must change line 1 with your correct LDAP Path

Const LDAPPath = "LDAP://DC=MyDomain,DC=Local"

0
 
x-menIT super heroCommented:
..I'll try and get you the 2nd version today
0
 
cmdownAuthor Commented:
Thanks x-men
 
0
 
x-menIT super heroCommented:
and for the Extra request:

remember to change line 1 with your correct LDAP Path

Const LDAPPath = "LDAP://DC=MyDomain,DC=Local"

and line 3 with the file name (".\MyList.csv",) ... the .\ means current directory (where the script is run)

ee2.vbs
0
 
cmdownAuthor Commented:
Thanks x-men
On running ee2, it generates an error on line 17, with strComputer containing the name of a long defunct server - removed from the domain circa 3 years ago.  Where is it getting this name from?
0
 
cmdownAuthor Commented:
ee1 runs but returns an odd result as below:
OS version & service packs: Microsoft Windows XP Professional - 5.1.2600 - Service Pack 3
PDSK-Site1-Office1 does not exist in:
 LDAP://DC=MyDomain,DC=local
 The pc is a member of the domain.
0
 
x-menIT super heroCommented:
The strComputer is populated with each Active Directory that’s objectCategory='computer'

So my guess is that, the defunct server wasn’t deleted from AD.

“PDSK-Site1-Office1 does not exist in:
LDAP://DC=MyDomain,DC=local”

Means that the computer named PDSK-Site1-Office1 is not found under any OU in the MyDomain.local domain.

Maybe you should change the Const LDAPPath = "LDAP://DC=MyDomain,DC=Local" with your domain name.
0
 
cmdownAuthor Commented:
Sorry for the delay in replying x-men.  I'll have a look at the above - but I'm on leave until 7th June so it may not be until then.
0
 
x-menIT super heroCommented:
how did it work out?
0
 
cmdownAuthor Commented:
Hi x-men
Sorry for the delay. I've been off ill for a while.  Thanks for all your help with this one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.