Public/Jobs.ps1

<#
.SYNOPSIS
    Invokes a command as a background job.
.DESCRIPTION
    This function takes a script block and runs it as a background job.
.PARAMETER ScriptBlock
    The script block to run as a job.
.EXAMPLE
    Invoke-O365CommandAsJob -ScriptBlock { Get-SPOExternalSharingReport }
.NOTES
    This function can be used to run any long-running command in the background.
#>

function Invoke-O365CommandAsJob {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [scriptblock]$ScriptBlock
    )

    Write-Verbose "Starting job..."
    $Job = Start-Job -ScriptBlock $ScriptBlock
    Write-Verbose "Job started with ID: $($Job.Id)"
    return $Job
}