Reputation: 71
I have a requirement to run a background script from main script,
Main script:
Start-Job -ScriptBlock {
C:\Temp\EMEAProductRefreshApp.ps1
} -ArgumentList $server | Out-File -Append "C:\Temp\abc.txt"
Sub script:
"Came to sub script" | Out-File -Append "C:\Temp\abc.txt"
But this is not printing in outfile from subscript, please suggest.
Upvotes: 0
Views: 71
Reputation: 104
The background job is killed when the parent exits, you should wait for the completion using Wait-Job:
Start-Job -ScriptBlock { C:\Temp\EMEAProductRefreshApp.ps1 } -ArgumentList $server | Wait-Job | Out-File -Append "C:\Temp\abc.txt"
Upvotes: 1