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:
The otherWellKnownObjects attribute is of type ADSTYPE_DN_WITH_BINARY which unfortunately cannot be viewed or edited with ADSI Edit:
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:
$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
}
[...] script.First I read the the otherWellKnownObjects attribute with PowerShell (I wrote about that earlier).This returns a Collection that I walk backwards with a for loop, this is important when removing [...]