I am new to Powershell. I am trying to find out all local/domain users under all the local groups from different Windows machines.
I found below script for this purpose. When I run this script in Windows 7 Ultimate, it does not get any member properties (e.g. Name, Path) for local groups found in this machine.
Invoke-Command -ScriptBlock {
[ADSI]$S = "WinNT://$($env:computername)"
$S.children.where({$_.class -eq 'group'}) |
Select @{Name="Members";Expression={
[ADSI]$group = "$($_.Parent)/$($_.Name),group"
$members = $Group.psbase.Invoke("Members")
($members | ForEach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}) -join ";"}
}
} | Select Members
It seems that below line of code does not work(does not fetch properties (e.g. name ) of the user)
ForEach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}) -join ";"}
Same script works well in Windows 10 and Windows 2012.
I thank you in advance for your help.