⚙️ POWERSHELL RUNE DIFFICULTY: Archmage Behavioral

The Visitor of Configuration Audits

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Sysadmin Telepathy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// POWERSHELL PATTERN //
class IVisitor {
    [void] VisitServer([ServerNode]$server) { throw "Not Implemented" }
    [void] VisitWorkstation([WorkstationNode]$ws) { throw "Not Implemented" }
}

class INode {
    [void] Accept([IVisitor]$v) { throw "Not Implemented" }
}

class ServerNode : INode {
    [string]$Name
    ServerNode([string]$n) { $this.Name = $n }
    [void] Accept([IVisitor]$v) { $v.VisitServer($this) }
}

class WorkstationNode : INode {
    [string]$Name
    WorkstationNode([string]$n) { $this.Name = $n }
    [void] Accept([IVisitor]$v) { $v.VisitWorkstation($this) }
}

class SecurityAuditVisitor : IVisitor {
    [void] VisitServer([ServerNode]$server) {
        Write-Host "Auditing SERVER $($server.Name) for strict port rules." -ForegroundColor Red
    }
    [void] VisitWorkstation([WorkstationNode]$ws) {
        Write-Host "Auditing WORKSTATION $($ws.Name) for local admin usage." -ForegroundColor Yellow
    }
}

# Unleasing the auditor
$nodes = @(
    [ServerNode]::new("DC01"),
    [WorkstationNode]::new("DESKTOP-ABC")
)
$auditor = [SecurityAuditVisitor]::new()

foreach ($node in $nodes) {
    $node.Accept($auditor)
}

The Visitor pattern unleashes an external spectral auditor upon the node graph. Without altering the underlying Server or Workstation classes, it performs deep, targeted security divinations upon them.

Runic Tags: #powershell #sysadmin #behavioral #visitor #auditing