• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

query Windows 2003 account status

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.
3 Solutions
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)" & _
Set objRecordSet = objCommand.Execute

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

Just be sure to change the Domain  in the script
nav2567Author Commented:

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.
try this;

dsquery user -disabled -limit 0 | dsget user -samid > c:\disabledusers.txt
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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
Krzysztof PytkoSenior Active Directory EngineerCommented:
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)

+1 Krzysztof - go with Quest PowerShell for AD


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!

nav2567Author Commented:
Thanks a lot everyone.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now