Public/New-UserProvisioningSyncSessionOperationExcel.ps1

<#
.SYNOPSIS
Prints all planned operations to screen, including a summary over each attribute and method

.EXAMPLE
$Operations | New-UserProvisioningSyncSessionOperationExcel
#>

function New-UserProvisioningSyncSessionOperationExcel {
    [CmdletBinding(SupportsShouldProcess = $true)]

    Param(
        # The operation to show
        [Parameter(ValueFromPipeline = $true)]
        $Operation,

        [Parameter(Mandatory = $true)]
        [ValidatePattern("\.xlsx$")]
        [String] $Path
    )

    Begin {
        $ExcelOperations = @()
    }

    Process {
        $Operation.Parameters.GetEnumerator() | ForEach-Object {
            if ($_.Key -eq "Replace") {
                $_.Value.GetEnumerator() | ForEach-Object {
                    $ExcelOperations += @{
                        Identity  = $Operation.Identity
                        Action    = $Operation.Action
                        Attribute = $_.Key
                        OldValue  = $Operation.OldValues ? $Operation.OldValues[$_.Key] : $null
                        NewValue  = $_.Value
                    }
                }
            }
            elseif ($_.Key -eq "Clear") {
                $_.Value | ForEach-Object {
                    $ExcelOperations += @{
                        Identity  = $Operation.Identity
                        Action    = $Operation.Action
                        Attribute = $_
                        OldValue  = $Operation.OldValues ? $Operation.OldValues[$_] : $null
                        NewValue  = "<cleared>"
                    }
                }
            }
            elseif ($_.Key -eq "OtherAttributes") {
                $_.Value.GetEnumerator() | ForEach-Object {
                    $ExcelOperations += @{
                        Identity  = $Operation.Identity
                        Action    = $Operation.Action
                        Attribute = $_.Key
                        OldValue  = $Operation.OldValues ? $Operation.OldValues[$_.Key] : $null
                        NewValue  = $_.Value ?? "<null>"
                    }
                }
            }
            else {
                $ExcelOperations += @{
                    Identity  = $Operation.Identity
                    Action    = $Operation.Action
                    Attribute = $_.Key
                    OldValue  = $Operation.OldValues ? $Operation.OldValues[$_.Key] : $null
                    NewValue  = $_.Value ?? "<null>"
                }
            }
        }
    }

    End {
        $ExcelOperations | Select-Object Identity, Action, Attribute, OldValue, NewValue | Export-Excel -Path $Path -AutoSize -TableName "UserProvisioningOperations" -WorksheetName "Operations" -ClearSheet
    }
}