Powershell 搜索帐户-此操作返回,因为超时时间已过期

Powershell 搜索帐户-此操作返回,因为超时时间已过期,powershell,active-directory,timeout,Powershell,Active Directory,Timeout,我有以下代码: Search-ADAccount -AccountExpiring -TimeSpan "90" -ResultPageSize:100 -ErrorAction SilentlyContinue | where {$_.samaccountname.StartsWith("X") -or $_.samaccountname.StartsWith("Y")} | Select-Object samaccountname,Name,AccountExpiration

我有以下代码:

Search-ADAccount -AccountExpiring -TimeSpan "90" -ResultPageSize:100 -ErrorAction SilentlyContinue |
    where {$_.samaccountname.StartsWith("X") -or $_.samaccountname.StartsWith("Y")} |
    Select-Object samaccountname,Name,AccountExpirationDate |
    Export-Csv $PSScriptRoot\Results\AD_Expiration_Dates_Accounts_Next_90_days_$((Get-Date).ToString('dd_MM_yyyy')).csv -NoTypeInformation -Append
无论是否使用
-ResultPageSize:
选项,我都会不断收到标题中提到的错误

有趣的是,当我更改
-TimeSpan
值时,我会得到更多或更少的值,因此数据似乎是一致的,但它总是以相同的错误结束

问题是,我不确定我能相信这些价值观;即使删除选项
-ErrorAction SilentlyContinue
,我也不会得到任何其他错误或信息


有人对此有任何意见吗?

在本例中,最好使用
Get ADUser
对所有需要的条件进行适当筛选,而不是返回大量结果,然后对其使用
where
子句

也考虑使用<代码>搜索范围< /代码>选项来限制OUU搜索(如果所有目标帐户都处于特定的OU)。< /P> 我会先省去

select
语句,看看您是否获得了所需的帐户(在这种情况下,您不需要在筛选后使用
-properties AccountExpirationDate


您的目标是找到90天内到期的ADUser帐户吗?如果是这样,为什么不使用
Get-ADUser
cmdlet?嘿,达斯,你正在搜索的OU/域中有多少用户?完美,它可以工作!非常感谢你。我使用了
getaduser
方法,但速度非常慢。问题是我用的是
Where
,而不是像
那样的
$now = get-date
$90days = (get-date).adddays(90)
get-aduser -filter '(AccountExpirationDate -gt $now) -and (AccountExpirationDate -le $90days) -and (samAccountName -like "X*" -or sAMAccountName -like "Y*" )' -properties AccountExpirationDate 
| Select-Object samaccountname,Name,AccountExpirationDate