StartRunbook--v2-3.psm1

$FunctionScriptName = "StartRunbook--v2-3"
Write-Verbose "Import-Start| [$($FunctionScriptName)]"

# Import-Function -Scope "Generic" -Function "Write-Pretty" -Version "1.X"
# Import-Module $HelperDir\returnVar2Output.psm1

function StartRunbook {
    <#
        .SYNOPSIS
            Hello world runbook
        .PARAMETER useCentralConfigDefaults
            true => Shows infos about common CentralConfig variables
            If not run with the CentralConfig - leave blank
 
        .NOTES
            AUTHOR: Ken Dobrunz // Ken.Dobrunz@Direkt-Gruppe.de | Direkt Gruppe
            WEBSITE: http://kensmagic.site
 
            LASTEDIT: 12.08.2021 - Version: 2.3
        #>

    Param(
        [Parameter()]$RunbookIdentifier,
        [Parameter()]$Version,
        [Parameter()]$PVersion,
        [Parameter()]$OutConfig = $OutConfig,
        [Parameter()]$CentralReturnVar = $returnVar,
        [Parameter()]$TriggerMetadata = $TriggerMetadata,
        [Parameter()]$TimeTrack = $TimeTrack,
        [Parameter()][string]$Message
    )
    Write-Debug "[StartRB] Start"
    # Setting global available starttime variable
    $global:RunbookStartTime = (Get-Date).ToLocalTime()
    
    if(!$OutConfig) {
        $OutConfig = @{}
        $OutConfig.OutHost = $true
    }

    $Output = @()
    if($TriggerMetadata) { $Output += "AZFunction name: $($TriggerMetadata.FunctionName)" }
    $Output += "Current time [$($RunbookStartTime.ToString("dddd, yyyy MMM dd HH:mm:ss"))]"

    #* Use returnVar from CentralConfig
    if($CentralReturnVar){
        $outputCentral = returnVar2Output -returnVar $CentralReturnVar
        $Output += $outputCentral.rawoutput_all
        $Output += $outputCentral.rawoutput_direct
    }
    
    #* TimeTrack
    if($TimeTrack) {
        $TimeTrackQM = TimeTrack -Measure
        $Output += "- Runtime until now: [$TimeTrackQM] minutes"
    }

    if($Message){$Output += $Message}

    $Output | Write-Pretty `
        -Header $RunbookIdentifier `
        -HeaderVersion ($Version + "@ PV: " + $PVersion) `
        -HeaderPrefix "Start Runbook:" `
        -OutConfig $OutConfig `
        -EmptyLinesBeforeAfter

    Write-Debug "[StartRB] End"
} 

Export-ModuleMember -Function *
Write-Verbose "Import-END| [$($FunctionScriptName)]"