I was able to fix my issue by using the code below after recreating the Keys and Managed Service Accounts containers in Active Directory. Current state just outputs the current configuration of OtherWellKnownObjects and change would be made. Uncomment the Set-ADobject lines to actually make the change to reassign the SID to the container locations.
Param (
[bool] $ProcessManagedServiceAccounts = $true,
[bool] $ProcessKeys = $true
)
$DomainDN = (Get-ADDomain).distinguishedName
(Get-ADObject -filter "objectClass -eq 'domainDns'" -Properties otherwellknownobjects).otherwellknownobjects
if ($ProcessManagedServiceAccounts) {
# Handle Managed Service Accounts
$TargetOWKOIDString = "1EB93889E40C45DF9F0C64D23BBB6237" # Identifier for wellknown SID (Managed Service Accounts).
$TargetOWKOTemplate = "B:32:$TargetOWKOIDString`:{0}" # String.Format replacable string.
$TargetDN = "CN=Managed Service Accounts,$DomainDN"
$OtherWellKnownObjectsOG = (Get-ADObject -filter "objectClass -eq 'domainDns'" -Properties otherwellknownobjects).otherwellknownobjects
$TargetOWKOIndex = $OtherWellKnownObjectsOG.IndexOf( $OtherWellKnownObjectsOG.where({ $PSItem -like "*$TargetOWKOIDString*" })[0])
Write-Host "`nIndex in OWKO for Managed Service Accounts is $TargetOWKOIndex"
Write-Host "If updating - would set OWKO for Keys to $TargetOWKOTemplate"
#Set-ADObject -Identity $DomainDN -Add @{'otherwellknownobjects' = ($TargetOWKOTemplate -f "$TargetDN")} -Remove @{'otherwellknownobjects' = $OtherWellKnownObjectsOG[$TargetOWKOIndex]}
}
if ($ProcessKeys) {
# Handle Keys
$TargetOWKOIDString = "683A24E2E8164BD3AF86AC3C2CF3F981" # Identifier for wellknown SID (Keys).
$TargetOWKOTemplate = "B:32:$TargetOWKOIDString`:{0}" # String.Format replacable string.
$TargetDN = "CN=Keys,$DomainDN"
$OtherWellKnownObjectsOG = (Get-ADObject -filter "objectClass -eq 'domainDns'" -Properties otherwellknownobjects).otherwellknownobjects
$TargetOWKOIndex = $OtherWellKnownObjectsOG.IndexOf( $OtherWellKnownObjectsOG.where({ $PSItem -like "*$TargetOWKOIDString*" })[0])
Write-Host "Index in OWKO for Keys is $TargetOWKOIndex"
Write-Host "If updating - would set OWKO for Keys to $TargetOWKOTemplate"
#Set-ADObject -Identity $DomainDN -Add @{ 'otherwellknownobjects' = ($TargetOWKOTemplate -f "$TargetDN") } -Remove @{ 'otherwellknownobjects' = $OtherWellKnownObjectsOG[$TargetOWKOIndex] }
}