Kev*_*inW 5 powershell active-directory
我试图搜索在指定日期之后创建的用户,但它总是不返回任何结果。如果我将-gt/ge 更改为 -lt/le它会正确提取结果,所以这应该是可行的。我知道我可以过滤所有内容,然后执行Where-Object 来过滤gt/ge,但我确实需要过滤器发生在服务器端。
关于如何在不执行Where-Object 或使用Get-QADUser 的情况下成功实现这一点的任何想法?
更新 2015.01.23:并不总是出现此错误,但它有助于指出问题:Get-ADUser:此操作由于超时期限已过期而返回
$Today = Get-Date -year (Get-Date).Year -Month (Get-Date).Month -Day (Get-Date).Day -Hour 00 -Minute 00 -Second 00
$StartDate = $Today.AddDays(-3)
$inputProperties = @(
"samaccountname"
"employeeid"
"title"
"enabled"
"manager"
"whencreated"
)
Get-ADUser -Filter {(whencreated -ge $StartDate)} -Properties $inputProperties
Run Code Online (Sandbox Code Playgroud)
小智 0
我也尝试了你的代码,效果很好。另外,您可以将变量更改$Today为$Today = (Get-Date).date,它会得到相同的结果。如果您收到超时错误,可以尝试将具有列出的属性的用户列表保存到变量中,然后对其进行过滤?
$Today = (Get-Date).date
$StartDate = $Today.AddDays(-3)
$inputProperties = @(
"samaccountname"
"employeeid"
"title"
"enabled"
"manager"
"whencreated"
)
$Users = Get-ADUser -Filter {(whencreated -ge $StartDate)} -Properties $inputProperties
$Users | ? { $_.whencreated -ge $StartDate }
Run Code Online (Sandbox Code Playgroud)
如果仍然失败,请尝试设置ResultSetSize参数。如果仍然出现超时错误,那么您就知道还有另一个问题。
Get-ADUser -ResultSetSize 1 -Filter {(whencreated -ge $StartDate)} -Properties $inputProperties
Run Code Online (Sandbox Code Playgroud)
编辑:天哪,没有意识到这篇文章已经有 7 年了。我会留下我的答案,以防它对偶然发现这个问题的人有所帮助。
| 归档时间: |
|
| 查看次数: |
4401 次 |
| 最近记录: |