![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| | |||||||
| | Vista - problem exporting OU users with filter = array("user") command |
| |
| 02-17-2009 | #1 |
| | problem exporting OU users with filter = array("user") command Hello Scripters. I have a single windows 2003 ad server with exchange 2003 installed in a testbed. I am trying to write a script to list all users in a a specific OU. So far my script will list all objects in an ou. But if I add the "objOU.filter=Array("user") command , it gives me not only the users in the ou but also the computer accounts. I have one user account and one computer account and when I run this code it lists BOTH the user AND the computer account. What am I doing wrong if I only want it to list the user accounts? here is my code ------------------------------------------------------------------ Set objOU = GetObject("LDAP://OU=student,OU=HS,DC=mydomain,DC=com") objOU.filter= Array("User") For Each obj In objOU WScript.Echo obj.cn Next ------------------------------------------------------------------- I have googled everything I can get my hands on and all seem to say that filter=Array("user") should be sufficient ... any feedback would be appreciated. -MC |
| My System Specs |
| 02-17-2009 | #2 |
| | Re: problem exporting OU users with filter = array("user") command "M.C.625569" <MCAntropy@xxxxxx> wrote in message news:7827e400-2201-4da7-90ab-5e32ee82dc23@xxxxxx Quote: > Hello Scripters. > > I have a single windows 2003 ad server with exchange 2003 installed in > a testbed. > I am trying to write a script to list all users in a a specific OU. So > far my script will list all objects in an ou. But if I add the > "objOU.filter=Array("user") command , it gives me not only the users > in the ou but also the computer accounts. > > I have one user account and one computer account and when I run this > code it lists BOTH the user AND the computer account. What am I doing > wrong if I only want it to list the user accounts? > > here is my code > > ------------------------------------------------------------------ > > Set objOU = GetObject("LDAP://OU=student,OU=HS,DC=mydomain,DC=com") > objOU.filter= Array("User") > > For Each obj In objOU > WScript.Echo obj.cn > Next > > ------------------------------------------------------------------- > > I have googled everything I can get my hands on and all seem to say > that filter=Array("user") should be sufficient ... > > any feedback would be appreciated. > > -MC objectClass attribute is multi-valued. For user objects objectClass = top, person, organizationalPerson, user. For computer objects objectClass = top, person, organizationalPerson, user, computer. If you filter on objectClass = computer, you get only computers. objectClass = group yields only groups. But objectClass = user yields both user and computer objects. The best solution I know for your snippet is to check the Class property method of the object. This returns the most specific value of the objectClass attribute. That is, for computer objects it returns "computer", but for user objects it returns "user". For example: ======== Set objOU = GetObject("LDAP://OU=student,OU=HS,DC=mydomain,DC=com") objOU.filter= Array("User") For Each obj In objOU If (obj.Class = "user") Then WScript.Echo obj.cn End If Next ========= The comparison is case sensitive. For organization unit objects the Class method returns "organizationalUnit". -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
| My System Specs |
| 02-17-2009 | #3 |
| | Re: problem exporting OU users with filter = array("user") command Thanks very much. On Feb 17, 4:51*pm, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > "M.C.625569" <MCAntr...@xxxxxx> wrote in message > > news:7827e400-2201-4da7-90ab-5e32ee82dc23@xxxxxx > > > Quote: > > Hello Scripters. Quote: > > I have a single windows 2003 ad server with exchange 2003 installed in > > a testbed. > > I am trying to write a script to list all users in a a specific OU. So > > far my script will list all objects in an ou. But if I add the > > "objOU.filter=Array("user") command , it gives me not only the users > > in the ou but also the computer accounts. Quote: > > I have one user account and one computer account and when I run this > > code it lists BOTH the user AND the computer account. *What am I doing > > wrong if I only want it to list the user accounts? Quote: > > here is my code Quote: > > ------------------------------------------------------------------ Quote: > > Set objOU = GetObject("LDAP://OU=student,OU=HS,DC=mydomain,DC=com") > > objOU.filter= Array("User") Quote: > > For Each obj In objOU > > WScript.Echo obj.cn > > Next Quote: > > ------------------------------------------------------------------- Quote: > > I have googled everything I can get my hands on and all seem to say > > that filter=Array("user") should be sufficient ... Quote: > > any feedback would be appreciated. Quote: > > -MC > The problem is that computer objects have objectClass "user". The > objectClass attribute is multi-valued. For user objects objectClass = top, > person, organizationalPerson, user. For computer objects objectClass = top, > person, organizationalPerson, user, computer. > > If you filter on objectClass = computer, you get only computers. objectClass > = group yields only groups. But objectClass = user yields both user and > computer objects. > > The best solution I know for your snippet is to check the Class property > method of the object. This returns the most specific value of the > objectClass attribute. That is, for computer objects it returns "computer", > but for user objects it returns "user". For example: > ======== > Set objOU = GetObject("LDAP://OU=student,OU=HS,DC=mydomain,DC=com") > objOU.filter= Array("User") > > For Each obj In objOU > * * If (obj.Class = "user") Then > * * * * WScript.Echo obj.cn > * * End If > Next > ========= > The comparison is case sensitive. For organization unit objects the Class > method returns "organizationalUnit". > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > -- |
| My System Specs |
![]() |
| Thread Tools | |
| |
| Similar Threads for: problem exporting OU users with filter = array("user") command | ||||
| Thread | Forum | |||
| WLM "there was a problem sending the command to the program" | Live Mail | |||
| Array indexing: Want to say "Item #2 through the rest of the array." | PowerShell | |||
| Vista Upgrade fails at "Gathering Files" when two users share the same user profile (ProfileImagePath). Message: "the upgrade was cancelled". | Vista installation & setup | |||
| User Accounts and UAC Strange Behaviour, Users are not shown under "Manage another account" | Vista account administration | |||
| "Open command prompt here" and "Copy as path" | Vista performance & maintenance | |||