fix(preflight): accept tokenGroups as SecurityIdentifier objects

The replication-rights pre-check cast every tokenGroups entry to byte[], which fails when the
ActiveDirectory module already returns SecurityIdentifier objects ("Cannot convert S-1-5-32-545 ... to
System.Byte[]"), so the check was skipped with a warning. Handle both forms.
This commit is contained in:
2026-11-06 08:08:06 +01:00
parent e270b9ab21
commit 8356cfc23d
+7 -3
View File
@@ -82,9 +82,13 @@ function Test-ReplicationPermissions {
# Look up by DistinguishedName (unambiguous) rather than re-deriving the username format.
$adUserWithTokenGroups = Get-ADUser -Identity $adUser.DistinguishedName -Server $Server -Credential $Credential `
-Properties tokenGroups -ErrorAction Stop
foreach ($sidBytes in $adUserWithTokenGroups.tokenGroups) {
$sid = New-Object System.Security.Principal.SecurityIdentifier(@([byte[]]$sidBytes), 0)
[void]$callerSids.Add($sid.Value)
# The ActiveDirectory module returns these as SecurityIdentifier objects (raw byte arrays on some builds).
foreach ($tokenGroup in $adUserWithTokenGroups.tokenGroups) {
if ($tokenGroup -is [System.Security.Principal.SecurityIdentifier]) {
[void]$callerSids.Add($tokenGroup.Value)
} else {
[void]$callerSids.Add((New-Object System.Security.Principal.SecurityIdentifier(@([byte[]]$tokenGroup), 0)).Value)
}
}
# adminCount=1 means SDProp is managing this account; it runs every 60 min and can