Skip to content

Instantly share code, notes, and snippets.

@zjorz
Last active July 10, 2025 19:59
Show Gist options
  • Select an option

  • Save zjorz/30e2eb106ab19527973dfca126fd81bf to your computer and use it in GitHub Desktop.

Select an option

Save zjorz/30e2eb106ab19527973dfca126fd81bf to your computer and use it in GitHub Desktop.
Bad Successor - ADDING/ENABLING BLOCK
# ==============================================================================
# Bad-Successor-ENABLING-BLOCK
# Setting systemOnly For 'CN=ms-DS-Managed-Account-Preceded-By-Link' To **TRUE**
# ==============================================================================
#
# SOURCE: https://gist.github.com/zjorz/30e2eb106ab19527973dfca126fd81bf
#
# WARNING: This Code Can ONLY Be Used When The W2K25 AD Schema Has Been Implemented! There IS NO Check To Validate This!
# WARNING: Membership of Schema Admins Is Required
# WARNING: The Actual Schema Master MUST Be Online And It Must Be Recognized As The Schema Master By Other RWDCs (i.e., "Initial synchronization" Must Have Taken Place And NO Recent Events With ID 2092 Exist About The FSMO Role: CN=Schema,CN=Configuration,DC=<FOREST>,DC=<TLD>)
# WARNING: AD Replication MUST BE In A Healthy State
#
<#
MIT License
Copyright (c) 2025 Semperis Technologies Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
DISCLAIMER: This project is licensed under the terms of the MIT license, and
is provided for educational and informational purposes only. It is intended
to promote awareness and responsible remediation of security vulnerabilities
that may exist on systems you own or are authorized to test. Unauthorized use
of this information for malicious purposes, exploitation, or unlawful access
is strictly prohibited. Semperis does not endorse or condone any illegal
activity and disclaims any liability arising from misuse of the material.
Additionally, Semperis does not guarantee the accuracy or completeness of the
content and assumes no liability for any damages resulting from its use.
#>
Invoke-Command -ScriptBlock {
Clear-Host
$systemOnly = $true
$thisADForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$rootDSE = [ADSI]"LDAP://$($thisADForest.SchemaRoleOwner.Name)/RootDSE"
$rootDSE.Put("schemaUpgradeInProgress", 1)
$rootDSE.SetInfo()
$msDSManagedAccountPrecededByLinkDN = "CN=ms-DS-Managed-Account-Preceded-By-Link,$($thisADForest.Schema.Name)"
Write-Host "Reconfiguring '$msDSManagedAccountPrecededByLinkDN'" -ForegroundColor Magenta
Write-Host " > Setting 'systemOnly' To '$($systemOnly.ToString().ToUpper())'" -ForegroundColor Yellow
Write-Host ""
$msDSManagedAccountPrecededByLink = [ADSI]"LDAP://$($thisADForest.SchemaRoleOwner.Name)/$msDSManagedAccountPrecededByLinkDN"
$msDSManagedAccountPrecededByLink.Put("systemOnly", $($systemOnly.ToString().ToUpper()))
$msDSManagedAccountPrecededByLink.SetInfo()
$rootDSE = [ADSI]"LDAP://$($thisADForest.SchemaRoleOwner.Name)/RootDSE"
$rootDSE.Put("schemaUpgradeInProgress", 0)
$rootDSE.SetInfo()
Write-Host "Reviewing Configuration Of '$msDSManagedAccountPrecededByLinkDN'" -ForegroundColor Magenta
$msDSManagedAccountPrecededByLink = [ADSI]"LDAP://$($thisADForest.SchemaRoleOwner.Name)/$msDSManagedAccountPrecededByLinkDN"
Write-Host " > 'systemOnly'........: $($msDSManagedAccountPrecededByLink.systemOnly)" -ForegroundColor Yellow
Write-Host ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment