Skip to content

Instantly share code, notes, and snippets.

@HarmJ0y
Created September 17, 2015 22:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarmJ0y/4226349db644e6549605 to your computer and use it in GitHub Desktop.
Save HarmJ0y/4226349db644e6549605 to your computer and use it in GitHub Desktop.
Translate-Canonical
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