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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
yehudahaCommented:
can you give example to exectly what you want
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.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.