functions/general/Beautify-AzurePIMTestResult.ps1

function Beautify-AzurePIMTestResult
{
    <#
        .SYNOPSIS
            Beautifies the returned output of the Test-AzurePIMRESOURCE functions.
 
        .PARAMETER TestResult
            The input test result object.
 
        .PARAMETER FunctionName
            Name of the function which returned the output.
 
        .PARAMETER DoNotShowPropertyChanges
            Do not print property changes from the test result object.
 
        .EXAMPLE
            PS> Test-AzurePIMGroup | Beautify-AzurePIMTestResult
    #>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [object] $TestResult,
        [string] $FunctionName = "AzurePIM",
        [switch] $DoNotShowPropertyChanges,
        [switch] $DoNotShowNoActionRequired
    )
    
    process
    {
        if ($DoNotShowNoActionRequired) {
            if ($TestResult.ActionType -ne "NoActionRequired") {
                Write-PSFMessage -Level Host -FunctionName $FunctionName -String "AzurePIM.TestResult.BeautifySimple" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $TestResult.ActionType, (Get-ActionColor -Action $TestResult.ActionType)
                if (!$DoNotShowPropertyChanges) {
                    if ($TestResult.ActionType -eq "Update") {
                        foreach ($change in $TestResult.Changes) {
                            foreach ($action in $change.Actions.Keys) {                        
                                $value = $change.Actions[$action] | ConvertTo-Json -Compress -Depth 8
                                Write-PSFMessage -Level Host -FunctionName $FunctionName -String "AzurePIM.TestResult.BeautifyPropertyChange" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $change.Property, $action, $value
                            }
                        }
                    }
                }
            }
        }
        else {
            Write-PSFMessage -Level Host -FunctionName $FunctionName -String "AzurePIM.TestResult.BeautifySimple" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $TestResult.ActionType, (Get-ActionColor -Action $TestResult.ActionType)
            if (!$DoNotShowPropertyChanges) {
                if ($TestResult.ActionType -eq "Update") {
                    foreach ($change in $TestResult.Changes) {
                        foreach ($action in $change.Actions.Keys) {                        
                            $value = $change.Actions[$action] | ConvertTo-Json -Compress -Depth 8
                            Write-PSFMessage -Level Host -FunctionName $FunctionName -String "AzurePIM.TestResult.BeautifyPropertyChange" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $change.Property, $action, $value
                        }
                    }
                }
            }
        }
    }
}