【发布时间】:2017-05-12 16:02:27
【问题描述】:
我正在尝试使用以下代码验证本地用户凭据:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName)
$status=$DS.ValidateCredentials($UserName, $Password)
我收到以下错误:
Exception calling "ValidateCredentials" with "2" argument(s): "The specified network name is no longer available.
"
At line:1 char:1
+ $ds.ValidateCredentials('User','Password')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PrincipalOperationException
请帮我解决这个问题。
提前致谢
注意:我没有在所有机器上都收到此错误。在 87 台机器中,我仅在 12 台机器中就遇到了这个错误。
【问题讨论】:
-
在 12 台计算机上,它无法正常工作,您能否 ping 通
$ComputerName提供的名称? -
是的,服务器正在 ping。这些命令在服务器本身内执行
-
嗨。我之前试过。它没有帮助。该代码给出了与上述相同的错误
标签: powershell powershell-3.0 credentials windows-server-2012-r2 powershell-4.0