Scripting against AD

G

Guest

Hi
I have checked out all the script examples on Microsofts TechNet site, but I don't find what I'm looking for
I want to read out from W2K-server Active Directory different kind of information based upon the sAMAccountName
I manage to read out the information but only based upon the "cn".

As long as I set strName = "jack russel" I get the information. But if I change to strName = "jackr" It says "No such object!
jackr is the sAMAccountName!

I also want to skip the strContainer - because the users could be anywhere in the AD

Can anyone help me please

Here is the sample script

strContainer = "ou=IT,ou=L,ou=NatverkA,ou=Org
strName = "jack russel

' Connect to an objec
Set objRootDSE = GetObject("LDAP://rootDSE"
If strContainer = "" The
Set objItem = GetObject("LDAP://" &
objRootDSE.Get("defaultNamingContext")
Els
Set objItem = GetObject("LDAP://cn=" & strName & "," & strContainer & "," &
objRootDSE.Get("defaultNamingContext")
End I

WScript.Echo "Sökt namn: " & strNam

'strSamName = objItem.Get("sAMAccountName"
'WScript.Echo "Kortnamn från AD: " & strSamNam

'strname = objItem.Get("sAMAccountName"
'WScript.Echo "Kortnamn från AD: " & strnam

strComonName = objItem.Get("cn"
WScript.Echo "cn: " & strComonNam

strmail = objItem.Get("mail"
WScript.Echo "mail: " & strmail
 
P

Paul

When I think I know what an attribute is but it is not working out like I
thought I use ADSI edit. Add ADSI edit to your MMC and "Select a well known
Naming Context" - Domain. Browse to the container that contains Jack
Russell (My daughter has one of these dogs and it is an absolute psycho!).
Right click on the user object and scroll through the attribute editor and
I'm betting what you think the object value is, is different than expected.


ÿ
Paul Bergson MCT, MCSE, CNE, CNA, CCA


Johank said:
Hi,
I have checked out all the script examples on Microsofts TechNet site, but
I don't find what I'm looking for.
I want to read out from W2K-server Active Directory different kind of
information based upon the sAMAccountName.
I manage to read out the information but only based upon the "cn".

As long as I set strName = "jack russel" I get the information. But if I
change to strName = "jackr" It says "No such object!"
 
M

Matthew Rimer [MSFT]

Setting strName to "jackr" isn't returning the object because the
GetObject() call to which you're passing it takes the distinguished name
(DN) of the object. The DN is the string like "CN=Jack Russel,
ou=IT,ou=L,ou=NatverkA,ou=Org, DC=....".

To find an object based on the value of the samAccountName attribute
requires sending a search request to Active Directory. ADSI, which is the
set of client-side interfaces for accessing Active Directory that you're
using in your script, exposes a couple of search interfaces. For scripting,
you can use the ADO search interface. There's a lot of material on using
ADSI to search the directory under
http://msdn.microsoft.com/library/en-us/adsi/adsi/searching_active_directory.asp?frame=true.
There's additional information about searching Active Directory at
http://msdn.microsoft.com/library/en-us/ad/ad/searching_active_directory.asp?frame=true.

When searching, you'd specify a search filter like "(samAccountName=jackr)".

Searching also solves your second problem: not needing to specify
strContainer. When you search, you can specify how deep the search should
go. If you specify a "subtree" search, the search will include not just the
container you specify, but all containers nested under that container (as
well as any containers nested under those, and so on). So for your example,
you'd use your code for retrieving the defaultNamingContext to set the base
of the search, specify a scope of subtree to search all the containers under
that, and use "(samAccountName=jackr)" as the filter.

- Matthew Rimer
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Johank said:
Hi,
I have checked out all the script examples on Microsofts TechNet site, but
I don't find what I'm looking for.
I want to read out from W2K-server Active Directory different kind of
information based upon the sAMAccountName.
I manage to read out the information but only based upon the "cn".

As long as I set strName = "jack russel" I get the information. But if I
change to strName = "jackr" It says "No such object!"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top