LDAP Filter用法
#根据Pager过滤域用户 $pagers = gc D:\Operations\tmp\u.txt foreach ($p in $pagers) { $user = Get-ADUser -Filter "pager -eq '$($p)'" -Properties pager -searchbase ",ou=yy,dc=ux,dc=yy,dc=com" if ($user -ne $null) {$user.pager + "," + $user.SamAccountName + "," + $user.UserPrincipalName |Out-File D:\Operations\tmp\ctz2.csv -Append} else {$p|Out-File D:\\tmp\ctz2.csv -Append} }
#查找非禁用账号&非密码永不过期&上次修改密码时间早于2018年3月4日的用户 $d = get-date "2018/3/4 14:12:24" $ys = Get-ADUser -Filter 'Enabled -eq "true" -and PasswordNeverExpires -eq "false" -and pwdLastSet -lt $d' -Properties PasswordLastSet -SearchBase "OU=yy,dc=ux,dc=xx,dc=com"
#查询3天内创建邮箱的用户 $d = (Get-Date).adddays(-3) $ys = Get-ADUser -Filter 'Enabled -eq $true -and msExchWhenMailboxCreated -ne "$null" -and msExchWhenMailboxCreated -ge $d' -Properties msExchWhenMailboxCreated $ys.Count
#查询employeeNumber为空的用户 $ua = Get-aduser -searchbase "OU=Sys,DC=yx,DC=com" -Filter 'Enabled -eq $true' -properties employeeNumber | ? {$_.employeeNumber -eq $null} $ua.count $ua = Get-aduser -searchbase "OU=Sys,DC=yx,DC=com" -Filter 'Enabled -eq $true -and employeeNumber -notlike "*"' -properties employeeNumber $ua.count $ua = Get-aduser -searchbase "OU=Sys,DC=yx,DC=com" -Filter { (Enabled -eq $true) -and (-not(employeeNumber -ne "$null"))} -properties employeeNumber $ua.count