IN_LOCALGROUP
Summary
Description
Identification
PowerShell
Active Directory Module
function Find-IN_LOCALGROUP {
[CmdletBinding()]
param([string]$SearchBase,[string[]]$ComputerName,[string]$OutputPath = "LocalGroupMembers.csv",[System.Management.Automation.PSCredential]$Credential)
Import-Module ActiveDirectory -ErrorAction Stop
if (-not $ComputerName) {
$adFilter = 'Enabled -eq $true'
$ComputerName = if ($SearchBase) {Get-ADComputer -Filter $adFilter -SearchBase $SearchBase -Properties Name |Select-Object -ExpandProperty Name} else {Get-ADComputer -Filter $adFilter -Properties Name |Select-Object -ExpandProperty Name}}
$scriptBlock = {
param($comp)
$groups = Get-LocalGroup -ErrorAction SilentlyContinue
foreach ($group in $groups) {
$members = Get-LocalGroupMember -Group $group.Name -ErrorAction SilentlyContinue
foreach ($member in $members) {
$isDomain = $false
if ($member.PSObject.Properties['PrincipalSource']) {$isDomain = ($member.PrincipalSource -eq 'ActiveDirectory')} else {$cn = $env:COMPUTERNAME;$isDomain = $member.Name -notmatch "^(NT AUTHORITY|BUILTIN|$([regex]::Escape($cn)))\\"}
if ($isDomain) {
[PSCustomObject]@{
ComputerName = $comp
GroupName = $group.Name
MemberName = $member.Name
MemberType = $member.ObjectClass
}}}}}
$icmParams = @{
ScriptBlock = $scriptBlock
ErrorAction = 'Stop'}
if ($Credential) { $icmParams.Credential = $Credential }
$results = foreach ($c in $ComputerName) {try {Invoke-Command -ComputerName $c @icmParams -ArgumentList $c} catch {Write-Host "Unable to connect to $c" -ForegroundColor Red}}
$results | Where-Object { $_ } | Select-Object ComputerName, GroupName, MemberName, MemberType | Export-Csv -Path $OutputPath -NoTypeInformation}.NET Directory Services
Active Directory Users and Computers

Exploitation
Mitigation

Detection
Event ID
Description
Fields/Attributes
References
References
Last updated
Was this helpful?