如何通过PowerShell显示本地组的成员

时间:2013-12-05 09:52:16

标签: powershell printing membership

我尝试了以下脚本,并获取了该组的成员。

$CompStat = Get-WmiObject win32_computersystem;
$Localhst = $CompStat.Name;
$Computer = [ADSI]('WinNT://'+$localhst+',computer');
$group = [ADSI]('WinNT://'+$Localhst+'/Remote Desktop Users,group');
$Members = @($group.psbase.Invoke("Members"));
$Members | ForEach-Object {$MemberNames += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null);}

但成员没有显示出来。如何打印成员?

1 个答案:

答案 0 :(得分:1)

只需在脚本末尾添加Write-Host $MemberNames