-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADUserOwner.ps1
42 lines (41 loc) · 1.26 KB
/
Get-ADUserOwner.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.Synopsis
Checks who owns the user object in Active Directory
.DESCRIPTION
Performs a lookup of the owner in the ACL of the user object in Active Directory
.EXAMPLE
Get-ADComputerOwner $Users
.EXAMPLE
Get-ADComputerOwner "User1", "User2"
#>
function Get-ADUserOwner
{
[CmdletBinding()]
Param
(
#$Users - Single or array of computers to search
[Parameter(Mandatory=$false,
ValueFromPipeline,
ValueFromPipelineByPropertyName=$true)]
[string[]]$Users
)
Begin {}
Process{
foreach ($user in $users){
try {
$use = Get-ADUser $user -ErrorAction Stop
$usepath = "AD:$($use.DistinguishedName.ToString())"
$owner = (Get-Acl -Path $usepath).Owner
$properties = @{Username = $user
Owner = $owner}
} catch {
$properties = @{Username = $user
Owner = $owner}
} finally {
$obj = New-Object -TypeName psobject -Property $properties
Write-Output $obj
} #End Finally
} #End Foreach
} #End Process
End{}
} #End Function