PowerShell Workflow getting suspended on its own while it is run via scheduled job in task scheduler

464 Views Asked by At

I have a created a script using PSworkflow which collects VM/license/network/mpp etc details from 13 VCenters and output all details in csv files. This script running fine when I manually run it in normal ps session (user interactive session) but when task scheduler schedule gets triggered then PSworkflow job submitted gets suspended on its own and does not give error as to why it suspended the PSWF job.

Here is how it is configured in task scheduler. - Created a batch file which launches powershell script. Below is the command powershell.exe -Command "& 'XXX\YYY.ps1'" 1>"ZZZ\PPP_log_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt" 2>&1 - In task scheduler action, mentioned this batch file to trigger on a schedule.

Here is the code for defining workflow:::

workflow cons {
    param ($HN,$consec,$OUTPUT_DIR)
    parallel {
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $HN -Session $Using:consec | out-null
            VMLicense }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $HN -Session $Using:consec | out-null
            getdsusage }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMPartInfo }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMNWinfra }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            mppstate }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMDiskinfra }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMInfo }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMInfra }
        inlinescript { $OUTPUT_DIR=$Using:OUTPUT_DIR
            $HN=$Using:HN
            connect-viserver -Server $Using:HN -Session $Using:consec | out-null
            VMSnapshot }
    }
}

Here is the code for launching pswf jobs for each VCenters:::

foreach ($vc in $InputScript) {
$HN=$vc.HN
$User=$vc.User
$Password=$vc.Password
$consec = GetCon    ## "GetCon" is custom function which has just connect-viserver command and its args.#
$job1=$HN.split('.')[0] + '_'  +  (get-date -format yyyyMMddss)
cons -HN $HN -consec $consec -OUTPUT_DIR $OUTPUT_DIR -asjob -JobName $job1
}

get-job | wait-job | export-csv $OUTPUT_DIR\log001.csv -NoTypeInformation

Here is the error message, I am getting when this task is triggered from task scheduler:

WARNING: One or more jobs are in a suspended or disconnected state, and cannot continue without additional user input.

Specify the -Force parameter to continue to a completed, failed, or stopped state. An error occurred while calling tracking participants causing the instance to be aborted. See the inner exception for more details. + CategoryInfo : InvalidResult: (:) [], OperationCanceledException + FullyQualifiedErrorId : JobStateFailed

0

There are 0 best solutions below