Solved

User in AD enabled yes / no

Posted on 2012-03-22
19
497 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:P-R-W
  • 7
  • 7
  • 2
  • +2
19 Comments
 

Expert Comment

by:Elohir
ID: 37752148
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
 
LVL 17

Expert Comment

by:Premkumar Yogeswaran
ID: 37752956
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37753755
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
 

Expert Comment

by:Elohir
ID: 37754508
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
 

Author Comment

by:P-R-W
ID: 37766753
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37766874
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37766901
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
 

Author Comment

by:P-R-W
ID: 37768522
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
 
LVL 17

Expert Comment

by:Premkumar Yogeswaran
ID: 37776756
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:P-R-W
ID: 37799900
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37800093
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
 

Author Comment

by:P-R-W
ID: 37800125
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37800201
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37800209
In fact easier than that, try issuing this:

dsquery user -name <yourDomainAdminUserName>

That should return the LDAP string to the Domain Admins container.
0
 

Author Comment

by:P-R-W
ID: 37800232
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
 
LVL 10

Expert Comment

by:Alan_White
ID: 37800279
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
 

Author Comment

by:P-R-W
ID: 37800475
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
 
LVL 6

Accepted Solution

by:
Ganesamoorthy S earned 500 total points
ID: 37869058
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
 

Author Closing Comment

by:P-R-W
ID: 37950950
Sorry for the delay, have been away for a few weeks. But glad to say that the last command worked.

Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now