Solved

query Windows 2003 account status

Posted on 2011-09-19
7
259 Views
Last Modified: 2012-05-12
I have a txt file which lists about 300 entries of samids.  Is there a way I can display the status of the samid (Active or Disable) and the samid itself?

We have WIN2003 AD environment.

Many Thanks.
0
Comment
Question by:nav2567
7 Comments
 
LVL 10

Accepted Solution

by:
SuperTaco earned 200 total points
Comment Utility
this will give you a listing of al disbled user account in AD

On Error Resume Next

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = _
    "<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)" & _
        "(userAccountControl:1.2.840.113556.1.4.803:=2));Name;Subtree"  
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop


Just be sure to change the Domain  in the script
0
 

Author Comment

by:nav2567
Comment Utility
Thanks.  

Can the above display a list of samids?

I am not good at VB.  Do you know how to put them together using dsquery & dsget?  I tried but not successful.
0
 
LVL 10

Expert Comment

by:SuperTaco
Comment Utility
try this;

dsquery user -disabled -limit 0 | dsget user -samid > c:\disabledusers.txt
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Expert Comment

by:SuperTaco
Comment Utility
For active users only try

dsquery * -filter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))"  > c:\domainusers.txt

copy and past this to a notepad first to take out the wraparound
0
 
LVL 39

Assisted Solution

by:Krzysztof Pytko
Krzysztof Pytko earned 150 total points
Comment Utility
Use this simple syntax in a batch file on a DC or any workstation with Administrative Tools installed.

Sample batch file

@echo off

for /f %%i in (text-file-with-samids.txt) do dsquery user -samid %%i | dsget user -fn -ln -samid -disabled >>c:\users-status.txt

save it in the same location where txt file with users is and run from command-line that batch. You will get on C-Drive text file with results (First Name, Last Name, login and account status)

You can also use for that Quest PowerShell module for AD (if you're interested, let me know)

Regards,
Krzysztof
0
 
LVL 6

Assisted Solution

by:netjgrnaut
netjgrnaut earned 150 total points
Comment Utility
+1 Krzysztof - go with Quest PowerShell for AD

http://www.quest.com/powershell/activeroles-server.aspx

If you want all the AD users, along with the status, just run

Get-QADUser | select SamAccountName,DisplayName,AccountIsDisabled | ft -auto

Open in new window


If you want to use your text file, write a little PowerShell script like this:

$UserList = gc "C:\somewhere\userlist.txt"
ForEach ($User in $UserList) {
    Get-QADUser -SamAccountName $User | 
    select SamAccountName,DisplayName,AccountIsDisabled | ft -auto
}

Open in new window


The output will be an easy to read table.  If you need output to a CSV or TXT file, let me know!

Hope that helps!



0
 

Author Closing Comment

by:nav2567
Comment Utility
Thanks a lot everyone.
0

Featured Post

Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …

744 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

12 Experts available now in Live!

Get 1:1 Help Now