Created
January 8, 2020 10:36
-
-
Save indented-automation/629a00167a74e9cb3329eabd6662bc0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ADAttributeAlias { | |
<# | |
.SYNOPSIS | |
Gets the names of the aliased attributes from the ActiveDirectory module. | |
.DESCRIPTION | |
Users reflection to discover the names of the attribute aliases available to filters. | |
.EXAMPLE | |
Get-ADAttributeAlias | |
Displays the atttribute aliases available for User objects. | |
.EXAMPLE | |
Get-ADAttributeAlias -ObjectClass Group | |
Displays the attribute aliases available for Group objects. | |
#> | |
[CmdletBinding()] | |
param ( | |
[ValidateSet('User', 'Computer', 'Group', 'ServiceAccount', 'Principal', 'Account')] | |
[String]$ObjectClass = 'User' | |
) | |
$requestedType = 'AD{0}' -f $ObjectClass | |
$namespace = 'Microsoft.ActiveDirectory.Management' | |
if ($instanceType = '{0}.{1}' -f $namespace, $requestedType -as [Type]) { | |
$type = '{0}.Commands.{1}Factory[{0}.{1}]' -f @( | |
$namespace | |
$requestedType | |
) -as [Type] | |
do { | |
$nestedTypeName = '{0}PropertyMap' -f $type.Name -replace 'Factory.+\d' | |
if ($nestedType = $type.GetNestedType($nestedTypeName, 'NonPublic,Static')) { | |
$nestedType = $nestedType.MakeGenericType($instanceType) | |
foreach ($field in $nestedType.GetFields('Public, Static')) { | |
$field.GetValue($null) | |
} | |
} | |
$type = $type.BaseType | |
} until ($type.BaseType -eq [Object]) | |
} else { | |
Write-Warning ('Cannot find type for {0}' -f $ObjectClass) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment