# mohsinis/sql-server-rename-manager architecture

> Architecture diagram of the GitHub repository mohsinis/sql-server-rename-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohsinis/sql-server-rename-manager
- Repository: https://github.com/mohsinis/sql-server-rename-manager

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Engine"
        Script["Complete-SqlRename.ps1"]:::core
        Params["/Parameters: NewServerName, RenameComputer, RemoteServers/"]:::param
        subgraph "Modules"
            SMO["SMO Module"]:::module
            Registry["Registry Provider"]:::module
            Net["Networking Cmdlets"]:::module
            RenameComp["Rename-Computer Cmdlet"]:::module
            Backup["Backup & Safety Subsystem"]:::module
        end
    end

    subgraph "Target Resources"
        SQLInst["SQL Server Instance"]:::resource
        WinOS["Windows OS"]:::resource
        LocalAlias["Local Alias Store (Registry)"]:::resource
        RemoteAlias["Remote Alias Store (Registry)"]:::resource
        SysDB["System Databases"]:::resource
    end

    subgraph "External Dependencies"
        DomainDC["Domain Controller"]:::external
        Network["Network (SMB, SQL Ports)"]:::external
        Credentials["Credentials (Local/Admin, Domain Admin)"]:::external
    end

    subgraph "Documentation"
        README["README.md"]:::doc
        LICENSE["LICENSE"]:::doc
    end

    %% Flows
    Params --> Script
    Script -->|Invoke SMO Rename| SMO -->|SMO API| SQLInst
    Script -->|Invoke Rename-Computer| RenameComp -->|Reboot| WinOS
    Script -->|Registry Provider| Registry -->|Update Local Alias| LocalAlias
    Script -->|SMB/Remote Registry| Net -->|Write Remote Alias| RemoteAlias
    Script -->|Backup & Safety| Backup -->|Backup/Restore| SysDB

    %% External
    DomainDC -.-> Script
    Network -.-> Net
    Credentials -.-> Script

    %% Click Events
    click Script "https://github.com/mohsinis/sql-server-rename-manager/blob/main/Complete-SqlRename.ps1"
    click README "https://github.com/mohsinis/sql-server-rename-manager/blob/main/README.md"
    click LICENSE "https://github.com/mohsinis/sql-server-rename-manager/tree/main/LICENSE"

    %% Styles
    classDef core fill:#D0E8FF,stroke:#0066CC,color:#003366;
    classDef module fill:#E6F2FF,stroke:#3399FF,color:#0066CC;
    classDef resource fill:#E8FFE8,stroke:#33CC33,color:#006600;
    classDef external fill:#FFF4E6,stroke:#FF9900,color:#CC6600;
    classDef doc fill:#F2F2F2,stroke:#999999,color:#666666;
    classDef param stroke:#0066CC,stroke-dasharray: 5 5,color:#003366;
```
