Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Created January 8, 2020 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indented-automation/629a00167a74e9cb3329eabd6662bc0c to your computer and use it in GitHub Desktop.
Save indented-automation/629a00167a74e9cb3329eabd6662bc0c to your computer and use it in GitHub Desktop.
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