Link to home
Start Free TrialLog in
Avatar of Xeronimo
XeronimoFlag for Luxembourg

asked on

calling a function with Start-Job?

Hi,

I've got a ps1 file with a couple of functions inside. Now I'd like to run one of these functions as a job. Is that possible? (I know how to run the whole script as a job but I'd like to know if it's possible to run just one function as a job) Thanks
Avatar of ste5an
ste5an
Flag of Germany image

When you can run the whole script as job, then it's simple.. Just add a parameter to the script invocation, when run as job. E.g. something like

<#
.SYNOPSIS
.DESCRIPTION
.NOTES
.PARAMETER ScheduledTask
#>

Param(
    [switch] $ScheduledTask = $False
)

#Requires -Version 5.0

Set-StrictMode -Version 2

Function ScriptMain() {
    If ($ScheduledTask) {
        TaskScheduledTask
    }
    Else {
        TaskNormalOperation
    }
}

Function TaskScheduledTask() {
}

Function TaskNormalOperation() {
}

. $PSCommandPath.Replace('.ps1', '.config.ps1')
Try {
    ScriptMain
}
Catch {
    Write-Error -Message $($_.Exception.Message)
    Exit 255
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial