windows - 远程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")
推荐阅读
- javascript - 如何在正则表达式中定义“不区分大小写”修饰符 i?
- scripting - 适合带有垂直对齐选项的框架
- javascript - React DatePicker 从父类获取状态
- postgresql - Postgres 中的触发器:在运行时按名称访问新字段
- python - 如何在 Python 中忽略 Sonarqube 的 1000 行限制:大于 1,000 已授权
- bash - 用于删除 aws s3 删除键名中包含空格的标记的 Bash 脚本
- javascript - 使用 OMDB API 时如何修复 401 错误?
- github - 个别存储库的 Github 语言下拉菜单是否损坏?
- android - Flutter,如何从 FCM 后台消息启动特定屏幕
- .net - 有没有办法使用 Google Sheets API v4 将图像上传到单元格?