Owner
Owner
Summary
Description
Identification
PowerShell
function Find-ADObjectOwner {
[CmdletBinding()]
param([string]$Target,[string]$SearchBase, [string]$OutputPath = "ADObjectOwner.csv")
Import-Module ActiveDirectory -ErrorAction Stop
try {
$baseDN = if ($SearchBase) { $SearchBase } else { (Get-ADRootDSE).defaultNamingContext }
if ($Target) {
try {
$objects = @( Get-ADObject -Identity $Target -Properties name,objectClass,distinguishedName )
} catch {
Write-Error "Target '$Target' not found or inaccessible: $($_.Exception.Message)"
return
}
} else {
Write-Host ("Enumerating objects under '{0}'..." -f $baseDN)
$objects = Get-ADObject -SearchBase $baseDN -LDAPFilter "(objectClass=*)" -ResultSetSize $null -Properties name,objectClass,distinguishedName
}
if (-not $objects) {
Write-Output "No objects found."
return
}
$i = 0
$total = $objects.Count
$results = foreach ($obj in $objects) {
$i++
if ($total -gt 1) {
Write-Progress -Activity "Reading owners" -Status "$i / $total : $($obj.DistinguishedName)" -PercentComplete (($i / $total) * 100)
}
try {
$acl = Get-Acl "AD:$($obj.DistinguishedName)"
$ownerRaw = $acl.Owner
$ownerName = $null
$ownerSid = $null
try {
if ($ownerRaw -match '^S-1-') {
$sid = New-Object System.Security.Principal.SecurityIdentifier($ownerRaw)
$ownerSid = $sid.Value
$ownerName = ($sid.Translate([System.Security.Principal.NTAccount])).Value
} else {
$ownerName = $ownerRaw
$nt = New-Object System.Security.Principal.NTAccount($ownerRaw)
$ownerSid = ($nt.Translate([System.Security.Principal.SecurityIdentifier])).Value
}
} catch {
$ownerName = $ownerRaw
$ownerSid = $ownerRaw
}
[PSCustomObject]@{
Name = $obj.Name
ObjectClass = ($obj.ObjectClass -join ';')
ObjectDN = $obj.DistinguishedName
Owner = $ownerName
OwnerSID = $ownerSid
}
} catch {
Write-Warning "Failed to read ACL for '$($obj.DistinguishedName)': $($_.Exception.Message)"
[PSCustomObject]@{
Name = $obj.Name
ObjectClass = ($obj.ObjectClass -join ';')
ObjectDN = $obj.DistinguishedName
Owner = $null
OwnerSID = $null
}
}
}
if ($OutputPath) {
$results | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
Write-Host "Owner information exported to '$OutputPath'"
} else {
return $results
}
} catch { Write-Error "Unhandled error: $($_.Exception.Message)"}
}
Exploitation
User
Group
Computer
Domain Object
GPO
Certificate Template
Delegated Managed Service Account
Mitigation

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