Solved

query Windows 2003 account status

Posted on 2011-09-19
7
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 10

Accepted Solution

by:
SuperTaco earned 200 total points
ID: 36563981
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
ID: 36564039
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
ID: 36564054
try this;

dsquery user -disabled -limit 0 | dsget user -samid > c:\disabledusers.txt
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:SuperTaco
ID: 36564063
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
ID: 36565635
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
ID: 36570010
+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
ID: 36922131
Thanks a lot everyone.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

761 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