1) I have a txt list with sAMAaccountNames

2) I need to query each account name and verify whether it is disabled

3) if the account is disabled, delete it from AD

I'll just delete them manually if there isn't another way, but first I need to check all the accounts in my list to see if they are disabled or not.

I have powershell v2.0 installed on this server and the DC is windows server 2003. The management server is windows server 2008.

I don't have the Active Directory module and I cannot install it either.

How can I do this with CMD/VBScript or powershell v2.0?

I have tried to run

dsquery -Filter "(userAccountControl:1.2.840.113556.1.4.803:=2)"

but I got the following error dsquery failed:The parameter is incorrect.:Incorrect object type specified. type dsquery /? for help.



Get-ADUser -Identity SamAccountName

returns the user object for SamAccountName.

To get the enabled property, use:

Get-ADUser -Identity SamAccountName | Select-Property Enabled.


(Get-ADUser -Identity SamAccountName).Enabled.

Edit: Or, lacking PowerShell AD module or PS 3.0+, use ADUC to implement an LDAP query, tweak the display columns to include what you want, then export the results to a file. Here's how (TechNet).

| improve this answer | |
  • -1, I specified that I don't have ActiveDirectory module installed, therefore I cannot use Get-ADuser. – DSKyo Sep 19 '16 at 7:42
  • Your 2008 server is missing a hotfix, which provides security upgrades to .NET 3.51. It also installs PS 3.0. – Xalorous Sep 21 '16 at 23:56
  • I agree, this server is missing many things, however it's not my say in what needs to be installed or not, I've gotta work with what I've been given. Thanks for trying to help tho. – DSKyo Sep 22 '16 at 13:26

It seems I missed a *. The correct code is:

dsquery * -Filter "(userAccountControl:1.2.840.113556.1.4.803:=2)"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.