-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGet-ADObjectFromPipeline.ps1
More file actions
49 lines (47 loc) · 1.81 KB
/
Copy pathGet-ADObjectFromPipeline.ps1
File metadata and controls
49 lines (47 loc) · 1.81 KB
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
47
48
49
function Get-ADObjectFromPipeline {
<#
.SYNOPSIS
Determines the type of an object passed to the pipeline and returns the object as an ADObject.
.DESCRIPTION
Determines the type of an object passed to the pipeline and returns the object as an ADObject. Potentially
useful for normalizing input to other functions.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
$Identity
)
begin {
Import-Module ActiveDirectory
}
process {
# Resolve identity type in process block where pipeline input ($Identity) is available.
if ($Identity -is [Microsoft.ActiveDirectory.Management.ADUser]) {
# We have an ADUser object
# Might want to normalize the type to an ADObject IF we can get sidHistory from an ADObject
}
if ($Identity -is [Microsoft.ActiveDirectory.Management.ADComputer]) {
# We have an ADComputer object
# Might want to normalize the type to an ADObject IF we can get sidHistory from an ADObject
}
if ($Identity -is [string]) {
# Find an AD object and determine its type
$Identity = Get-ADObject -Filter "Name -eq `"$Identity`""
}
$IdentityType = $Identity.ObjectClass
switch ($IdentityType) {
'user' {
# Not Complete
Get-ADUser -Identity $Identity -Properties PrimaryGroup,SidHistory
}
'computer' {
# Not Complete
Get-ADComputer -Identity $Identity -Properties PrimaryGroup,SidHistory
}
Default {
Write-Error "Identity type not supported."
}
}
}
}