PoshCode Archive  Artifact [f81fcc298b]

Artifact f81fcc298ba4b3f525e54c48a6781441a2fc980ca3d656b40e09600ca0a3ad5a:

  • File Find-Local-Group-Members.ps1 — part of check-in [c711125a5f] at 2018-06-10 14:26:25 on branch trunk — Amended line $ChildGroups = “Domain Admins”, “group two” to clear bug from my previous post :) (user: Hal Rottenberg size: 1449)

# encoding: ascii
# api: powershell
# title: Find Local Group Members
# description: Amended line $ChildGroups = “Domain Admins”, “group two” to clear bug from my previous post :)
# version: 0.1
# author: Hal Rottenberg
# license: CC0
# x-poshcode-id: 905
# x-archived: 2009-06-07T10:02:01
#
#
# 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"
$error.clear()
$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 ) {
	$MemberNames = @()
	$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"
	$Members = @($Group.psbase.Invoke("Members"))
	$Members | ForEach-Object {
		$MemberNames += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
	
	} 
         $errCount = $error.count
	$ChildGroups | ForEach-Object {
		$output = "" | Select-Object Server, Group, InLocalAdmin
		$output.Server = $Server
		$output.Group = $_
		If ($errCount -gt 0){$output.InLocalAdmin = "Connection Error!"}ELSE{$output.InLocalAdmin = $MemberNames -contains $_}
		Write-Output $output
	}
$error.clear()
}