Public/Get-PegasusSyncOperationStatistics.ps1

function Get-PegasusSyncOperationStatistics {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $Operation,

        [Parameter(Mandatory = $false)]
        [Switch] $OutputAzureDevOpsArtifact
    )

    Begin {
        $Operations = New-Object System.Collections.ArrayList
        $Statistics = @{
            "Create person"   = 0
            "Update person"   = 0
            "Delete person"   = 0
            "Create position" = 0
            "Update position" = 0
            "Delete position" = 0
            "Create orgunit"  = 0
            "Update orgunit"  = 0
            "Delete orgunit"  = 0
            "Delete"          = 0
            "Update"          = 0
            "Create"          = 0
        }
    }

    Process {
        if($Operation) {
            $Operations.Add($Operation) | Out-Null
        }

        if ($Operation.Type -and $Statistics.ContainsKey($Operation.Type)) {
            $Statistics[$Operation.Type] += 1
            $Statistics[$Operation.Type.Split(" ")[0]] += 1
        }
    }

    End {
        $Statistics

        if($OutputAzureDevOpsArtifact.IsPresent -and $Operations.Count -gt 0) {
            $Operations | ConvertTo-Json -Depth 10 | Out-File -FilePath "pegasus_sync_operations.json" -Force
            $Fullpath = Resolve-Path "pegasus_sync_operations.json"
            $Statistics | ConvertTo-Json -Depth 10 | Out-File -FilePath "pegasus_sync_operation_statistics.json" -Force

            Write-Host "##vso[artifact.upload artifactname=operations]$($Fullpath.Path)"
        }
    }
}