如何解决远程SAM用户查询
我正在尝试从远程Windows框中的本地SAM数据库查询用户信息。 我已经知道可以进行本地通话的语法了,但是对于远程通话,我似乎找不到正确的语法来连接到远程系统。
Add-Type -AssemblyName System.DirectoryServices.AccountManagement;
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine;
$User = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($ct,"sean");
$User;
用于远程连接的C#代码在这里:
PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Machine,"TAMERO","administrator","password");
我似乎无法为PS获得正确的语法。 有人做过吗?
解决方法
要在PowerShell中调用PrincipalContext
构造函数,请使用特殊的new()
静态方法:
#...
$principalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($ct,"Computername","Username","Password")
$User = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($principalContext,"targetSAMAccountName")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。