PoshCode Archive  Artifact Content

Artifact 5c0c84bb7ca5334988720e7387d344dd3d791817da49a932e85c21ac74b7c856:

  • File Seach-LocalGroupMember.ps1 — part of check-in [c16f385114] at 2018-06-10 13:02:23 on branch trunk — search users in the local administrators group on computers domain network (user: Angel-Keeper size: 1853)

# encoding: ascii
# api: powershell
# title: Seach-LocalGroupMember
# description: search users in the local administrators group on computers domain network
# version: 0.1
# type: function
# author: Angel-Keeper
# license: CC0
# function: Seach-LocalGroupMemberDomenNetwork
# x-poshcode-id: 1877
# x-archived: 2013-05-27T19:41:16
# x-published: 2010-05-26T23:10:00
#
#
function Seach-LocalGroupMemberDomenNetwork() {
param(
$Domen,
$User
)

function Ping ($Name){ 
    $ping = new-object System.Net.NetworkInformation.Ping
    if ($ping.send($Name).Status -eq "Success") {$True}
    else {$False} 
	trap {Write-Verbose "Error Ping"; $False; continue}
}

[string[]]$Info
[string[]]$Computers

if ($User){$Connection = Get-Credential -Credential $User}

$Computers = Get-QADComputer -Service $Domen -OSName '*XP*','*Vista*','*7*' -SizeLimit 0 -ErrorAction SilentlyContinue | 
			 Select-Object name -ExpandProperty name

Foreach ($Computer in $Computers){
	$Alive = Ping $Computer
	if ($Alive -eq "True"){
		
		if ($Connection) {
			Trap {Write-Host "Error WMI $Computer";Continue}
			$GroupName = Get-WmiObject win32_group -ComputerName $Computer -Credential $Connection | 
						Where-Object {$_.SID -eq 'S-1-5-32-544'} | 
						Select-Object name -ExpandProperty name
		}
		else {
		Trap {Write-Host "Error WMI $Computer";Continue}
			$GroupName = Get-WmiObject win32_group -ComputerName $Computer | 
						Where-Object {$_.SID -eq 'S-1-5-32-544'} | 
						Select-Object name -ExpandProperty name
		}
		
		if ($GroupName){
			$Users = ([ADSI]"WinNT://$Computer/$GroupName").psbase.invoke("Members") | 
						% {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
			$Info += $Users | % {$_ | Select-Object @{e={$Computer};n='Computer'},@{e={$_};n='Login'}}
		}
	}
}
$Info
}