如何使用powershell v2.0或CMD / VBS检查是否在AD中禁用了特定的用户帐户列表

1)我有一个tAM列表与sAMAaccountNames

2)我需要查询每个帐户名称,并validation它是否被禁用

3)如果账户被禁用,从AD中删除它

如果没有其他办法,我只是手动删除它们,但首先我需要检查我的列表中的所有帐户,看看他们是否被禁用。

我在这个服务器上安装了powershell v2.0,DC是windows server 2003.pipe理服务器是windows server 2008。

我没有Active Directory模块,也无法安装它。

我怎样才能做到这一点与CMD / VBScript或PowerShell的v2.0?

我试图跑

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

但我得到以下错误dsquery failed:The parameter is incorrect.:Incorrect object type specified. type dsquery /? for help. dsquery failed:The parameter is incorrect.:Incorrect object type specified. type dsquery /? for help.

看来我错过了* 。 正确的代码是:

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

电源shell

 Get-ADUser -Identity SamAccountName 

返回SamAccountName的用户对象。

要获取启用的属性,请使用:

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

要么

(Get-ADUser -Identity SamAccountName).Enabled

编辑:或者,缺lessPowerShell AD模块或PS 3.0+,使用ADUC来实现LDAP查询,调整显示列以包含所需内容,然后将结果导出到文件。 (TechNet)。