Created
November 22, 2022 14:35
-
-
Save IISResetMe/e831b2d3294f3f08084c671f8ef33eab to your computer and use it in GitHub Desktop.
Quick and dirty function to affect the same changes as redircmp.exe and redirusr.exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-ADPrincipalRedirection { | |
param( | |
[Parameter(Mandatory)] | |
$Domain, | |
[string] | |
$ComputersOU, | |
[string] | |
$UsersOU | |
) | |
$ErrorActionPreference = 'Stop' | |
$updated = $false | |
$updateWKO = { | |
param($Domain,$WKOKey,$Old,$New) | |
$params = @{ | |
Identity = $Domain | |
Remove = @{wellKnownObjects = "B:32:${WKOKey}:${Old}"} | |
Add = @{wellKnownObjects = "B:32:${WKOKey}:${New}"} | |
} | |
Set-ADObject @params | |
} | |
$DomainInfo = Get-ADDomain -Identity $Domain | |
if($PSBoundParameters.ContainsKey('ComputersOU')){ | |
$newTarget = Get-ADOrganizationalUnit -Identity $ComputersOU | |
Write-Verbose "Updating Computer Redirection target from '$($DomainInfo.ComputersContainer)' to '$($newTarget.distinguishedName)'" | |
& $updateWKO $DomainInfo 'AA312825768811D1ADED00C04FD8D5CD' $DomainInfo.ComputersContainer $newTarget.distinguishedName | |
$updated = $true | |
} | |
if($PSBoundParameters.ContainsKey('UsersOU')){ | |
$newTarget = Get-ADOrganizationalUnit -Identity $UsersOU | |
Write-Verbose "Updating User Redirection target from '$($DomainInfo.UsersContainer)' to '$($newTarget.distinguishedName)'" | |
& $updateWKO $DomainInfo 'A9D1CA15768811D1ADED00C04FD8D5CD' $DomainInfo.UsersContainer $newTarget.distinguishedName | |
$updated = $true | |
} | |
if(-not $updated){ | |
Write-Warning "No changes made, did you forget to include a target OU?" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment