-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADComputerOwnerV0.1.ps1
46 lines (45 loc) · 1.57 KB
/
Get-ADComputerOwnerV0.1.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
43
44
45
46
<#
.Synopsis
Checks who owns the computer object in Active Directory
.DESCRIPTION
Performs a lookup of the owner in the ACL of the computer object in Active Directory
.EXAMPLE
Get-ADComputerOwner $Computers
.EXAMPLE
Get-ADComputerOwner "Computer1", "Computer2"
#>
function Get-ADComputerOwner
{
[CmdletBinding()]
Param
(
#$computers - Single or array of computers to search
[Parameter(Mandatory=$false,
ValueFromPipeline,
ValueFromPipelineByPropertyName=$true)]
[string[]]$Computers
)
Begin {}
Process{
foreach ($computer in $computers){
try {
$comp = Get-ADComputer $computer -Properties Created -ErrorAction Stop
$comppath = "AD:$($comp.DistinguishedName.ToString())"
$owner = (Get-Acl -Path $comppath).Owner
$properties = @{Computername = $comp.Name
Owner = $owner
Created = [datetime]$comp.Created
Enabled = $comp.enabled}
} catch {
$properties = @{Computername = $comp.Name
Owner = $null
Created = $null
Enabled = $null}
} finally {
$obj = New-Object -TypeName psobject -Property $properties
Write-Output $obj
} #End Finally
} #End Foreach
} #End Process
End{}
} #End Function