Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Help me!

$
0
0

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!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>