PoshCode Archive  Artifact [36ff1b2962]

Artifact 36ff1b2962bdf0b1b6a9bd6fd6304578f319810ae96866e32edd190ed66b9862:

  • File compliance-settings.ps1 — part of check-in [e4c324a234] at 2018-06-10 13:52:24 on branch trunk — Find matching members in a local group (user: Hal Rottenberg size: 1257)

# encoding: ascii
# api: powershell
# title: compliance settings
# description: Find matching members in a local group
# version: 0.1
# author: Hal Rottenberg
# license: CC0
# x-poshcode-id: 5245
# x-archived: 2014-06-25T07:07:10
# x-published: 2014-06-18T12:27: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
	}
}