PoshCode Archive  Artifact [d98df3255b]

Artifact d98df3255b443318f63bbbe72e2878c7838ec09c1e0da97055f7036724dc6e87:

  • File Find-Local-Group-Members.ps1 — part of check-in [72a2ecd081] at 2018-06-10 13:07:46 on branch trunk — Find matching members in a local group (user: Hal Rottenberg size: 1262)

# encoding: ascii
# api: powershell
# title: Find Local Group Members
# description: Find matching members in a local group
# version: 0.1
# author: Hal Rottenberg
# license: CC0
# x-poshcode-id: 2240
# x-archived: 2016-03-07T00:25:33
# x-published: 2011-09-20T16:32:00
#
#
# Author: Hal Rottenberg
# Purpose: Find matching members in a local group
# Used tip from RichS here: http://powershellcommunity.org/Forums/tabid/54/view/topic/postid/1528/Default.aspx

# Change these two to suit your needs
$ChildGroups = "Domain Admins", "Group Two"
$LocalGroup = "Administrators"

$MemberNames = @()
# uncomment this line to grab list of computers from a file
# $Servers = Get-Content serverlist.txt
$Servers = $env:computername # for testing on local computer
foreach ( $Server in $Servers ) {
	$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"
	$Members = @($Group.psbase.Invoke("Members"))
	$Members | ForEach-Object {
		$MemberNames += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
	} 
	$ChildGroups | ForEach-Object {
		$output = "" | Select-Object Server, Group, InLocalAdmin
		$output.Server = $Server
		$output.Group = $_
		$output.InLocalAdmin = $MemberNames -contains $_
		Write-Output $output
	}
}