| Filter | 如 Enabled -eq $false;字符串要引号 |
|---|---|
| LDAPFilter | 如 (!(userAccountControl:1.2.840.113556.1.4.803:=2)) |
| 分页 | -ResultPageSize 1000 -ResultSetSize $null;导出 Export-Csv -NoTypeInformation |
常用示例
常用示例
# 找出禁用的用户
Get-ADUser -Filter 'Enabled -eq $false' -ResultPageSize 1000 | Select-Object Name, SamAccountName, DistinguishedName
# 邮箱以 @corp 结尾
Get-ADUser -Filter 'EmailAddress -like "*@corp.local"' -Properties EmailAddress | Select-Object Name, EmailAddress
# 导出完整清单
Get-ADUser -Filter * -Properties * | Select-Object SamAccountName, DisplayName, Department, Enabled, LastLogonDate | Export-Csv ad_users.csv -NoTypeInformation -Encoding UTF8过滤条件写错不会报错只是结果为空——用已知账号反向验证条件正确性。