P-R-W
asked on
User in AD enabled yes / no
Hello,
I have the following code:
Many thanks
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
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
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
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
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.
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.
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.
ASKER
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
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=
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
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
try:
dsquery group -samid "cn=Domain Admins,dc=xxx,dc=yyy" | dsget group -members | dsget user -disabled -display
Alan
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
ie. The cn=Domain Admins,dc=xxx,dc=yyy bit
ASKER
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?
What am I doing wrong?
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
SAMID cannot be the DN..
dsquery group -name "cn=Domain Admins,cn=Users,dc=xxx,dc=
try this one... changed samid to name...
Regards,
Prem
ASKER
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
dsquery group -name "cn=Domain Admins,cn=Users,dc=xxx,dc=
and get error: dsget failed:'Target object for this command' is missing
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.
dsquery user "ou=Domain Admins,ou=Users,dc=xxx,dc=
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.
ASKER
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
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
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.
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.
In fact easier than that, try issuing this:
dsquery user -name <yourDomainAdminUserName>
That should return the LDAP string to the Domain Admins container.
dsquery user -name <yourDomainAdminUserName>
That should return the LDAP string to the Domain Admins container.
ASKER
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?
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?
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
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
ASKER
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=preside nt,DC=corp
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=preside
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the delay, have been away for a few weeks. But glad to say that the last command worked.
Thanks!
Thanks!
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.