This script run OK.
$servers = 'SERVER01'
$grupo = 'Administrators'
$query = "Associators of {Win32_Group.Domain='$servers',Name='$grupo'} where Role=GroupComponent"
Get-WMIObject -query $query -computer $servers |
Select @{Name="Group";Expression={$grupo}},
@{Name="Members";Expression={$_.Caption}},
@{Name="Type";Expression={([regex]"User|Group").matches($_.__CLASS)[0].Value}},
@{Name="Computername";Expression={$_.__SERVER}} | Format-Table -auto
I see the members of "Administrator" local group from a one server. I need to see all localgroups and members. So i write this:
$servers = 'SERVER01'
$grupo = Get-WMIObject Win32_Group -computer $servers | where {$_.LocalAccount} | SELECT name
$grupo | foreach {
$query = "Associators of {Win32_Group.Domain='$servers',Name='$grupo'} where Role=GroupComponent"
Get-WMIObject -query $query -computer $servers |
Select @{Name="Group";Expression={$grupo}},
@{Name="Members";Expression={$_.Caption}},
@{Name="Type";Expression={([regex]"User|Group").matches($_.__CLASS)[0].Value}},
@{Name="Computername";Expression={$_.__SERVER}} | Format-Table -auto
}
When the script run fine i want to add foreach servers and i'll get all members and all localgroups from a list of my servers!
Thanks!