我想提出一个包含所有用户Name
,SamAccountName
和Description
的CSV文件,但我们注意到有几个人没有说明。我正在寻找的是如何编辑我现有的代码(我知道这是一个简单的方法,我只能记住它),这样就过滤了我的输出,所以它只显示没有描述的用户
Get-ADUser -Filter * -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { $_.Enabled -notlike "FALSE" } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"
答案 0 :(得分:0)
您需要在Where-Object
scriptblock中添加其他条件,因为您无法使用LDAP-Query AFAIK过滤空值。一个建议:
Get-ADUser -Filter * -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { $_.Enabled -notlike "FALSE" -and [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"
我个人也会将启用检查移动到Get-ADUser
中的过滤器以加快速度。现在DC只会向您启用已启用的用户而不是所有用户。尝试:
Get-ADUser -Filter { Enabled -eq $true } -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"