Link to home
Start Free TrialLog in
Avatar of redman20111
redman20111

asked on

List of server admin groups using Powershell

Hi

I have a couple of servers running Windows 2008 Server, they are running various applications for our company.

Within each server there is the Administrator group and also some specific  (local) groups for our company:

ITAdmins
Helpdesk Admins
Vendors

Every week, I would like to run a script that will pull the membership of the local groups on the server. I have an admin server running Powershell 2 and I was thinking of using this.

Please note, the groups I mentioned above aren't Domain Security/Distribution Groups within Active Directory, they are local groups on the servers themselves.

Thanks in advance for any assistance.
Avatar of x-men
x-men
Flag of Portugal image

$hostnames = get-content c:\hostnames.txt
Foreach ($Hostname in $hostnames) {

([ADSI]"WinNT://$Hostname/ITAdmins,group").psbase.Invoke("Members") |
    % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)}

([ADSI]"WinNT://$Hostname/"Helpdesk Admins",group").psbase.Invoke("Members") |
    % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)}

([ADSI]"WinNT://$Hostname/Vendors,group").psbase.Invoke("Members") |
    % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)}
}
ASKER CERTIFIED SOLUTION
Avatar of x-men
x-men
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of redman20111
redman20111

ASKER

Thanks, but these are local groups (i.e. not Domain Groups), so why are we using ADSI?
[ADSI] is the adapter, that establishes the connection to "WinNT://..." for local
Hi x-men thanks for your solution (copied below)...but are you able to explain how it works for me?

$hostnames = get-content c:\hostnames.txt
foreach ($hostname in $Hostnames) {"$hostname`tITAdmins`t$(([ADSI]"WinNT://$hostname/ITAdmins,group").psbase.Invoke("Members") | % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)})
$hostname`t"Helpdesk Admins"`t$(([ADSI]"WinNT://$hostname/"Helpdesk Admins",group").psbase.Invoke("Members") | % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)})
$hostname`t Vendors`t$(([ADSI]"WinNT://$hostname/Vendors,group").psbase.Invoke("Members") | % {$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)})
" }