How mohsinis/sql-server-rename-manager works
Project Type and Purpose
• This is an open-source PowerShell CLI utility.
• It automates SQL Server instance renaming and synchronizes SQL Native Client aliases across a set of Windows servers.
File Structure Analysis
• Top-level script: Complete-SqlRename.ps1.
• Supporting docs: README.md, LICENSE.
• No subdirectories—core logic lives entirely in one script.
Key Components to Model
a. PowerShell Script (Complete-SqlRename.ps1)
• Entrypoint: parameter parsing, logging, safety checks.
• Modules invoked:
• SQL Server Management Objects (SMO)
• Windows rename cmdlets
• Registry access via built-in PowerShell providers
• Networking cmdlets (Test-NetConnection, Get-Service)
b. SQL Server Instance(s)
• Local or remote SQL instances that will be renamed via sp_dropserver/sp_addserver.
• Require administrative connection.
c. Windows OS Rename Operation
• Optional system rename using Rename-Computer.
• Triggers a reboot.
d. SQL Native Client Aliases
• Stored in HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo on each server.
• Local registry updates.
• Remote updates via SMB (port 445) and remote registry.
e. Backup & Safety Subsystem
• System database backups before rename.
• Connection termination logic + retry loops.
• Emergency multi-user mode switchback.
f. External Services & Dependencies
• Domain controller for authentication.
• Network (SMB, SQL ports).
• Credentials: local admin, domain admin.
Relationships and Data Flows
• The PowerShell script orchestrates all operations:
→ Connects to SQL Server (SMO) → issues rename sp calls.
→ Optionally calls Rename-Computer → Windows Host changes.
→ Enumerates alias registry keys → writes new alias entries locally and pushes them remotely using SMB.
→ Initiates backups and runs recovery logic on failures.
[Script] ──SMO API──> [SQL Instance]
[Script] ──Rename-Computer──> [Windows OS]
[Script] ──Registry Provider──> [Local Alias Store]
[Script] ──SMB/Remote Registry──> [Remote Alias Stores]
[Script] ──Backup Cmdlets──> [System Databases]
Architectural Patterns & Design Principles
• Single-binary (script) orchestrator—no submodules or microservices.
• Procedural flow with clear safety checkpoints (backups, retries).
• Extensibility via well-defined parameter inputs.
• Idempotency focus: safe to re-run if partial progress occurred.
Essential Elements to Capture
• Entrypoint parameters → script orchestration.
• Safety mechanisms (backup, retry, emergency restore).
• External dependency boundaries (network ports, credentials).
• Remote vs. local alias update path.