我正在尝试从远程windows box上的本地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语法。以前有人这么做过吗?
发布于 2020-09-11 08:06:37
要在PowerShell中调用PrincipalContext构造函数,需要使用特殊的new()静态方法:
#...
$principalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($ct, "Computername", "Username", "Password")
$User = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($principalContext, "targetSAMAccountName")https://stackoverflow.com/questions/63839055
复制相似问题