Powershell 在获取ADUser时出错?

Powershell 在获取ADUser时出错?,powershell,active-directory,Powershell,Active Directory,有时: (Get-AdUser -filter * -server contoso.com).count 返回良好/正确的输出 有时我会: Local error Category Info : NotSpecified: (:) [Get-ADUser], ADException Fully Qualified Error ID : ActiveDirectoryServer:8251,Microsoft.ActiveDirectory.Management.Comm

有时:

(Get-AdUser -filter * -server contoso.com).count
返回良好/正确的输出

有时我会:

Local error
 
Category Info : 

NotSpecified: (:) [Get-ADUser], ADException  

Fully Qualified Error ID :
    
ActiveDirectoryServer:8251,Microsoft.ActiveDirectory.Management.Commands.GetADUser
有人能帮我一下吗?它不起作用了?
感谢

在这些错误情况下,您似乎没有导入AD模块
导入模块ActiveDirectory
,或者在未连接到AD域的计算机上尝试了此操作。另外,我会将代码行更改为
@(获取AdUser-filter*-server contoso.com)。
@()
强制输出为数组,即使它只有一个或根本没有项。那么在这种情况下,
.Count
不会失败。如果模块昨天在同一台计算机上工作,我肯定导入了该模块。。。我也尝试了你的数组建议,但似乎是cmdlet本身导致了错误“它昨天在同一台计算机上工作”lol并不意味着它今天就可以工作。你说它不管用,但它也管用?所以只是偶尔?枚举似乎遇到了问题。运行
$Error[0]| FL*-Force
以获取更多详细信息。如果我请求DC1.contoso.com->如果我请求DC2.contoso.com->它将不起作用