PowerShell,如果您不是域的一部分,是否可以将SID转换为ntaccount?

时间:2010-10-05 18:15:29

标签: powershell active-directory

我有这个powershell代码。

$securityidentifier = new-object security.principal.securityidentifier $sid
$user = ( $securityidentifier.translate( [security.principal.ntaccount] ) )

此代码仅适用于与我想将其转换为ntaccount的用户位于同一域中的计算机。

如果您不属于该域名,但是您拥有该域名的域名用户名和密码,是否可以将SID转换为ntaccount?

仍然是同样的错误。

Exception calling "Translate" with "1" argument(s): "Some or all identity references could not be translated." At C:\...\test.ps1:7 char:40 + $user = ( $securityidentifier.translate <<<< ( [security.principal.ntaccount] ) ) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

2 个答案:

答案 0 :(得分:0)

您是否尝试过将驱动器映射到域控制器,这会有效地缓存域用户的凭据?然后,这可以允许访问转换SID。我之前没有尝试过,但是值得一试。

答案 1 :(得分:0)

由于您不在域中,因此您的计算机不知道应该请求谁(哪个域控制器)来解析此SID。似乎Translatename方法没有服务器参数。

如果您使用WinApi,则可以:使用LookupAccountSid API(为 lpSystemName 参数指定域控制器)。