PoshCode Archive  Artifact [63923599e5]

Artifact 63923599e59bd72a57bcaf2db9577916453fe1613db6cdc7a4210676a2ddc06b:

  • File Find-Local-Group-Members.ps1 — part of check-in [ea3b485dc9] at 2018-06-10 14:26:23 on branch trunk — If you output the original script to a txt file you cannot tell if a remote PC is switched off. Script below will now report a “Connection Error” if network path is not found (user: Hal Rottenberg size: 1540)

# encoding: ascii
# api: powershell
# title: Find Local Group Members
# description: If you output the original script to a txt file you cannot tell if a remote PC is switched off.  Script below will now report a “Connection Error” if network path is not found
# version: 0.1
# author: Hal Rottenberg
# license: CC0
# x-poshcode-id: 904
# x-derived-from-id: 905
# x-archived: 2009-06-09T10:59:32
#
#
# 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",
$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()
}