Private/New-pseScheduledTaskPrincipal.ps1

Function New-pseScheduledTaskPrincipal {

    [cmdletbinding()]
    param (
        [parameter (Mandatory = $true)]
        [string]$RunAs,

        [switch]$RunWithHighestPrivilege
    )

    try {
        # Set the task run level
        $taskPrincipal = New-ScheduledTaskPrincipal -GroupId $RunAs -ea Stop -ev x

        # Run with highest privileges if selected
        if ($RunWithHighestPrivilege.IsPresent) {
            Write-Host "Run level set to 'Highest'" -ForegroundColor DarkGray
            $taskPrincipal.RunLevel = "Highest"
        } else {
            Write-Host "Run level set to 'Limited'" -ForegroundColor DarkGray
            $taskPrincipal.RunLevel = "Limited"
        }

        return $taskPrincipal

    } catch {
        Write-Error "Unable to set the task principal: $x" -stop
    }
}