How can I show a message to console when start script using Start-Job? I tried write-warning but don’t work.
Example:
# On file script.ps1
#dumb code here
write-warning "Success!"
#end file
PS> Start-Job script.ps1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Background jobs run in a separate PowerShell.exe process so the only way to get text from the background job code and display on the interactive console is to use
Receive-Job.In the background job code use
Write-Output "Success".Start-Job script.ps1 | Wait-Job | Receive-Jobwill display your message.