Private/Baseline/Get-AlzInitiatives.ps1

function Get-AlzInitiatives {
    <#
    .SYNOPSIS
        Extract ALZ initiatives from AzAdvertizer CSV data.
     
    .DESCRIPTION
        Scans the policyUsedInPolicySet column to identify all Azure Landing Zones (ALZ)
        initiatives referenced in the CSV. Parses DisplayName and Code from naming patterns.
     
    .PARAMETER CsvData
        Array of CSV rows from AzAdvertizer.
     
    .EXAMPLE
        $alzInitiatives = Get-AlzInitiatives -CsvData $polCsv
     
    .OUTPUTS
        Hashtable with initiative keys and metadata objects
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [object[]]$CsvData
    )
    
    $alzInitiativesFound = @{}
    
    Write-Host ""
    Write-Host "🔍 Scanning CSV for ALZ initiatives..." -ForegroundColor Cyan
    
    foreach ($row in $CsvData) {
        $used = [string]$row.policyUsedInPolicySet
        if ([string]::IsNullOrWhiteSpace($used)) { 
            continue 
        }
        
        foreach ($p in ($used -split ';')) {
            $p2 = $p.Trim()
            
            if ($p2 -like '* ALZ') {
                Write-Debug "Found ALZ initiative: $p2"
                
                # Parse pattern: "DisplayName (Code) ALZ"
                if ($p2 -match '^(?<disp>.+?)\s*\((?<code>[^)]+)\)\s*ALZ$') {
                    $disp = $Matches['disp'].Trim()
                    $code = $Matches['code'].Trim()
                    $key = if ($code) { $code } else { $disp }
                    
                    $alzInitiativesFound[$key] = [pscustomobject]@{
                        DisplayName = $disp
                        Code = $code
                    }
                } else {
                    # Simple pattern: "DisplayName ALZ"
                    $disp = $p2.Substring(0, $p2.Length - 4).Trim()
                    $alzInitiativesFound[$disp] = [pscustomobject]@{
                        DisplayName = $disp
                        Code = $null
                    }
                }
            }
        }
    }
    
    Write-Host (" └─ Found {0} ALZ initiatives in CSV" -f $alzInitiativesFound.Count) -ForegroundColor DarkCyan
    
    return $alzInitiativesFound
}