PowerShell 远程获取本地用户成员资格

标签 powershell get-wmiobject remotecommand memberof

这里需要一些帮助。

我需要使用 PowerShell 脚本获取远程计算机的本地用户列表以及他们属于哪个组。

我尝试过:

Get-LocalUser
Get-LocalGroup
Get-LocalGroupMember

另外:

gwmi win32_UserAccount
gwmi win32_group 

但是速度非常慢,并且提取的信息超出了要求,这会消耗时间。

我希望输出格式如下:

User     Memberof
------   --------------------
abc12    Administrators
efg23    remote desktop users
hij45    Administrators,Backup Operators,users
xyz56    remote desktop users,Backup Operators

提前致谢, 干杯。

最佳答案

我使用 ADSI,速度非常快。

$RemoteComputerName = 'RemoteComputer'
$LocalGroup = 'Remote Desktop Users'

$ADSI = [ADSI]("WinNT://$RemoteComputerName,Computer")
$Group = $ADSI.PSBase.Children.Find($LocalGroup,'Group')
$Group.PSBase.Invoke('Members').Foreach{ $_.GetType().InvokeMember('Name','GetProperty',$null,$_,$null) }

关于PowerShell 远程获取本地用户成员资格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49694710/

相关文章:

powershell - IF 语句在 Powershell 中不起作用

Powershell 2 和 .NET : Optimize for extremely large hash tables?

powershell - 如何向现有 PowerShell 对象添加成员?

Linux远程工具-winexe用户名/密码

powershell - 如何在 Powershell 中为命令 "ls -lrt"设置别名

azure - 编辑 Azure KeyVault secret 版本上的现有标记值

azure - 使用 Azure Active Directory 用户时,远程 WMI 查询失败并显示 'A security package specific error occurred'

powershell - 如何在Windows Server 2012中使用Powershell 5检查Windows服务的启动类型是 "auto"还是 "auto-delayed"

javascript - 将参数传递给 p :remoteCommand from JavaScript