I wanted to read the otherWellKnownObjects attribute from an Active Directory object.

In my case this was the Microsoft Exchange container in the Configuration partition:

image

The otherWellKnownObjects attribute is of type ADSTYPE_DN_WITH_BINARY which unfortunately cannot be viewed or edited with ADSI Edit:

There is no editor registered to handle this attribute type 

 

So I wrote a script to read the values with PowerShell but it's not very straightforward how to do this.

Reading the otherWellKnownObjects property returns a collection of IADsDNWithBinary interfaces but this interface is unknown in PowerShell.

Using reflection we can read the values:

powershell Download
$objCN = New-Object System.DirectoryServices.DirectoryEntry("LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local")
$gp = [Reflection.Bindingflags]::GetProperty

foreach ($objWKO in $objCN.otherWellKnownObjects)
{
    $objType = $objWKO.GetType()
    $DNString = $objType.InvokeMember("DNString", $gp, $null, $objWKO, $null)
    $BV = $objType.InvokeMember("BinaryValue", $gp, $null, $objWKO, $null)
    $Guid = [GUID][System.BitConverter]::ToString($BV).Replace("-", "")
    Write-Host "DNString=$DNString" -foregroundcolor Blue
    Write-Host "Guid=$Guid" -foregroundcolor Blue
}