User in AD enabled yes / no

Hello,

I have the following code:
Option Explicit
Dim strMember, strDNSDomain, strContainer
Dim objGroup, objRootDSE
Dim arrMemberOf, arrMemberOf2, arrMemberOf3, arrMemberOf4
Dim strList, strList2, strList3, strList4, arrGroup

' Bind to Active Directory' 
strContainer = "cn=Administrators,cn=Builtin, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' Get the Builtin Administrators group
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo "Members of Administrator groups " & vbCrLf
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList = strList & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList

' Get the Domain Administrators group
strContainer = "cn=Domain Admins,cn=Users, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf2 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf2
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList2 = strList2 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList2

' Get the Enterprise Administrators group
strContainer = "cn=Enterprise Admins,cn=Users, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf3 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf3
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList3 = strList3 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList3

' Get the Exchange Administrators group
strContainer = "cn=Exchange Organization Administrators,ou=Microsoft Exchange Security Groups, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf4 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf4
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList4 = strList4 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList4

Wscript.Quit

Open in new window

and it runs fine. It shows all users that are member of an administrator group. Problem is that I would like to see if the account is enabled or disabeld. Have been trying several things (like trying to get the objUser.AccountDisabled status) but no luck so far. Anybody ideas how to do it?

Many thanks
P-R-WAsked:
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.

ElohirCommented:
There should be an 'Enabled' property for the account object(s).  

Unfortunately, I do not believe that enumerating the members of the group using GetEx is going to give you "Account" objects.  So you may need to query each account individually in your code to obtain that property.
0
Premkumar YogeswaranSr. Analyst - System AdministratorCommented:
Instead of VB Script - You can achieve this in ds command

Check this link:

http://www.windowstricks.in/2010/01/to-get-members-status-from-active.html

Group name: sales_executes

Syntax:

dsquery group -samid “Group Pre-Win2k Name” | dsget group -members | dsget user -disabled -display

Example:

dsquery group -samid sales_executes | dsget group -members | dsget user -disabled -display

Regards,
Prem
0
Alan_WhiteCommented:
This page: http://www.itadmintools.com/2010/09/find-disabled-users-in-active-directory.html

Says that "Unfortunately, there is no attribute that holds the enabled/disabled status of the user. Suprising. It turns out that the disabled status is stored as a bit in the useraccountcontrol attribute. This attribute contains a number that is made up of binary bits, each having a different meaning."

And then goes on to provide a VBScript solution.

Hope that helps.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ElohirCommented:
When I use the New-ADUser Active Directory cmdlet in PowerShell 2.0, I am able to access the 'Enabled' property.  I would presume that Get-ADUser -Properties should also work, but I have not used it myself.
0
P-R-WAuthor Commented:
Hello Premglitz,
Thanks for you suggestion. I have tried to use dsquery but don't get any further. I try the following command:

dsquery group -samid "cn=Domain Admins,cn=Users,dc=xxx,dc=yyy" | dsget group -members | dsget user -disabled -display

Where xxx and yyy is my domian (fe microsoft.com).

But I get the error: dsget failed:'Target object for this command' is missing

Any ideas? Thanks
0
Alan_WhiteCommented:
It is unlikley that the Domain Admins container is below the Users container.

try:
dsquery group -samid "cn=Domain Admins,dc=xxx,dc=yyy" | dsget group -members | dsget user -disabled -display

Alan
0
Alan_WhiteCommented:
Here is some background on the LDAP Namespace Structure:  http://www.informit.com/articles/article.aspx?p=101405&seqNum=7

ie.  The cn=Domain Admins,dc=xxx,dc=yyy  bit
0
P-R-WAuthor Commented:
Thanks for the explanation of the LDAP structure, but when I look into the Attribute editor tab of the Domain Admins group the distinguished name is: CN=Domain Admins,CN=Users,DC=xxx,DC=yyy

What am I doing wrong?
0
Premkumar YogeswaranSr. Analyst - System AdministratorCommented:
Hi,

SAMID cannot be the DN..

dsquery group -name "cn=Domain Admins,cn=Users,dc=xxx,dc=yyy" | dsget group -members | dsget user -disabled -display

try this one... changed samid to name...

Regards,
Prem
0
P-R-WAuthor Commented:
Sorry for the delay in answer! Have tried:

dsquery group -name "cn=Domain Admins,cn=Users,dc=xxx,dc=yyy" | dsget group -members | dsget user -disabled -display

and get error: dsget failed:'Target object for this command' is missing
0
Alan_WhiteCommented:
Try this one:

dsquery user  "ou=Domain Admins,ou=Users,dc=xxx,dc=yyy" | dsget user -disabled -display

I tested the previous command in my environment and it failed.  I found that my Domain Admins container was actaully an OU.  My version is more simple that the previous one, I'm getting back the users in the Domain Admins OU and seeing if they are disabled.  Of course there may be non-Domain Admin users in this OU (unlikely) or Domain Admins that are not in this OU.

Anyway, the simplified version might be a good place to start.
0
P-R-WAuthor Commented:
Hello Alan,

You're right, lets first get the command to work and then I can go further, but also with this command I get an error: dsquery failed: Directory object not found.

Can it be that there is something in my AD or Windows server version that is blocking it? I'm running Windows SBS 2008

Thanks
0
Alan_WhiteCommented:
Refering to my previous post on LDAP syntaxm, it is important that you get the correct path to your container.  

If you look in ADU&C does the User container look like an OU or a Container?  Same for Domain Admins?  (the icon looks different, eg Builtin is a container and looks like a blank folder.  An OU has a little picture in the folder.
0
Alan_WhiteCommented:
In fact easier than that, try issuing this:

dsquery user -name <yourDomainAdminUserName>

That should return the LDAP string to the Domain Admins container.
0
P-R-WAuthor Commented:
If I do:

dsquery user -name administrator

I get a correct answer, but not the LDAP string to the domain admins container. When I do:

dsquery group -name "Domain Admins"

I also get an answer: both Domain Admins and Users are CN. Can it be that the | (pipe) might not work?
0
Alan_WhiteCommented:
The pipe does work for me.

When I run your dsquery group -name "Domain Admins" command I also get CN=Domain Admins, CN=Users but that is the group, not the container.  

Can you please run this command: dsquery user  "ou=Domain Admins,dc=xxx,dc=yyy"

And if you get something back, then run theis command: dsquery user  "ou=Domain Admins,dc=xxx,dc=yyy" | dsget user -disabled -display
0
P-R-WAuthor Commented:
When I run: dsquery user  "ou=Domain Admins,dc=xxx,dc=yyy" it gives me an error.

Sorry, maybe I'm confused about groups and containers ...
Domain Admins is a security group within the Users folder / container.
When I look at the distinguised name within the properties of Domain Admins it gives me:
CN=Domain Admins,CN=Users,DC=president,DC=corp
0
Ganesamoorthy STech LeadCommented:
Hi,

Use the below command

dsquery group -samid "Domain Admins" | dsget group -members | dsget user -disabled -display

http://www.windowstricks.in/2010/01/to-get-members-status-from-active.html
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
P-R-WAuthor Commented:
Sorry for the delay, have been away for a few weeks. But glad to say that the last command worked.

Thanks!
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
Active Directory

From novice to tech pro — start learning today.