How to display the members of a local group through powershell

4.4k views Asked by At

I have tried the following script and it fetched the members of the group.

$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);}

But the members are not getting displayed. How to print the members?

1

There are 1 answers

0
Ocaso Protal On BEST ANSWER

Just add a Write-Host $MemberNames at the end of your script