Created
September 17, 2015 22:39
-
-
Save HarmJ0y/4226349db644e6549605 to your computer and use it in GitHub Desktop.
Translate-Canonical
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 Translate-Canonical { | |
<# | |
.SYNOPSIS | |
Converts a user@fqdn to NT4 format. | |
.LINK | |
http://windowsitpro.com/active-directory/translating-active-directory-object-names-between-formats | |
#> | |
[CmdletBinding()] | |
param( | |
[String]$User | |
) | |
$Domain = $User.split("@")[0] | |
# Accessor functions to simplify calls to NameTranslate | |
function Invoke-Method([__ComObject] $object, [String] $method, $parameters) { | |
$output = $object.GetType().InvokeMember($method, "InvokeMethod", $NULL, $object, $parameters) | |
if ( $output ) { $output } | |
} | |
function Set-Property([__ComObject] $object, [String] $property, $parameters) { | |
[Void] $object.GetType().InvokeMember($property, "SetProperty", $NULL, $object, $parameters) | |
} | |
$Translate = new-object -comobject NameTranslate | |
try { | |
Invoke-Method $Translate "Init" (1, $Domain) | |
} | |
catch [System.Management.Automation.MethodInvocationException] { } | |
Set-Property $Translate "ChaseReferral" (0x60) | |
try { | |
Invoke-Method $Translate "Set" (5, $User) | |
(Invoke-Method $Translate "Get" (3)) | |
} | |
catch [System.Management.Automation.MethodInvocationException] { $_ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment