Link to home
Start Free TrialLog in
Avatar of cmdown
cmdown

asked on

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
Avatar of Mike Kline
Mike Kline
Flag of United States of America image

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
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.

can you give example to exectly what you want
ASKER CERTIFIED SOLUTION
Avatar of x-men
x-men
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
must change line 1 with your correct LDAP Path

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

..I'll try and get you the 2nd version today
Avatar of cmdown
cmdown

ASKER

Thanks x-men
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmdown

ASKER

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?
Avatar of cmdown

ASKER

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmdown

ASKER

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.
how did it work out?
Avatar of cmdown

ASKER

Hi x-men
Sorry for the delay. I've been off ill for a while.  Thanks for all your help with this one.