I have a Scheduled task that executes a powershell script.
regardless, I get log4net
output from the rest of the script. It is when the $job=Start-BitsTransfer
part runs that I get nothing.
If i just execute script in PShell
, works like a champ. The job controls/logic works and I get output.
When I run within a scheduled task, the SCRIPT scope (best I can tell from ss64.com/ps/syntax-scopes
) doesn't output and I can't really access or control.
Here is the part of the script that is killing me:
$log.Info("TestPath is:" +(Test-Path $DestDir\$file))
if (!(Test-Path $DestDir\$file))
{
$log.Info('COPY $SrcDir\$file - $DestDir\')
$job = Start-BitsTransfer -Asynchronous "$SrcDir\$file" "$DestDir\$file" -DisplayName $file
$log.Info("JUST RAN JOB")
$log.Info("JUST RAN JOB::jobstate =" +$(Get-Job -Name $file))
WHILE ( $job.JobState -eq 'Transferring' -or $job.JobState -eq 'Connecting' )
{
$log.Info("jobstate =" +$job.JobState)
Start-Sleep -Seconds 600
}
$log.Info("jobstate= " +$job.JobState+" -- starting Complete command")
TRY {
$log.Info("Completing Job= " +$job.JobState + " with ID: " +$(Get-BitsTransfer | select $_.JobID))
Get-BitsTransfer | complete-bitstransfer
$log.Info("Completed Job= " +$job.JobState)
} CATCH {
$log.Error("ERROR Completing Job " ) }
}
closest I've come to blog/article on what I need is here but didn't get me what I need (by warren f.) and a similar question here, - and here when submitting this on stackoverflow, but there was no resolution...
I've tried (what I can remember trying):
- using log4net in script
- sending output to file in scheduled task config
- set-psdebug -trace
- Warren F's article (linked above)
- sending job output to file in script code
AAARRRGGGG!! again, TIA.
njoylif
BTW, here is sample log output:
2016-11-09 17:06:34,222 [Pipeline Execution Thread] INFO TestPath is:False 2016-11-09 17:06:34,425 [Pipeline Execution Thread] INFO COPY \10.104.192.107\d$\BULocal\2016-10-30.bak - F:\BURemote\ 2016-11-09 17:06:34,519 [Pipeline Execution Thread] INFO JUST RAN JOB 2016-11-09 17:06:35,207 [Pipeline Execution Thread] INFO JUST RAN JOB::jobstate = 2016-11-09 17:06:35,207 [Pipeline Execution Thread] INFO jobstate= -- starting Complete command 2016-11-09 17:06:35,238 [Pipeline Execution Thread] INFO Completing Job= with ID: Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob Microsoft.BackgroundIntelligentTransfer.Management.BitsJob 2016-11-09 17:06:35,582 [Pipeline Execution Thread] INFO Completed Job=