Public/Invoke-KritTcmFromM365DscMigration.ps1

function Invoke-KritTcmFromM365DscMigration {
    <#
    .SYNOPSIS
        Wrapper for the Microsoft365DSC to TCM migration utility.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
    param(
        [Parameter(Mandatory)][string]$ConfigurationPath,
        [string]$OutputPath,
        [string]$ConverterPath,
        [string[]]$ArgumentList,
        [switch]$PassThru
    )

    if (-not (Test-Path -LiteralPath $ConfigurationPath)) {
        throw "ConfigurationPath was not found: $ConfigurationPath"
    }

    if (-not $ConverterPath) {
        $converterRoot = Get-KritTcmConstant -Name M365DscToTcmConverter
        return [pscustomobject]@{
            Action = 'Invoke-KritTcmFromM365DscMigration'
            Status = 'ConverterPathRequired'
            ConfigurationPath = (Resolve-Path -LiteralPath $ConfigurationPath).Path
            OutputPath = $OutputPath
            ConverterReference = $converterRoot
            Notes = 'Supply -ConverterPath after cloning or installing the Microsoft M365DSC-to-TCM conversion utility.'
        }
    }

    if (-not (Test-Path -LiteralPath $ConverterPath)) {
        throw "ConverterPath was not found: $ConverterPath"
    }

    $arguments = @('-InputPath', (Resolve-Path -LiteralPath $ConfigurationPath).Path)
    if ($OutputPath) { $arguments += @('-OutputPath', $OutputPath) }
    if ($ArgumentList) { $arguments += $ArgumentList }

    if ($PSCmdlet.ShouldProcess($ConverterPath, "Run M365DSC-to-TCM converter for $ConfigurationPath")) {
        $result = & $ConverterPath @arguments
        if ($PassThru) { return $result }
        [pscustomobject]@{
            Action = 'Invoke-KritTcmFromM365DscMigration'
            Status = 'Invoked'
            ConverterPath = (Resolve-Path -LiteralPath $ConverterPath).Path
            ConfigurationPath = (Resolve-Path -LiteralPath $ConfigurationPath).Path
            OutputPath = $OutputPath
        }
    }
}