I need to start a job on a remote computer and make it terminate asynchronously.
In other words, after successfully establishing a remote session I want to start a job on the remote computer and let it go on even after the session is closed, because it can take a long time.
The code I wrote looks like:
#
# Here I create my remote session $my_session
#
invoke-Command -Session $my_session -ScriptBlock {
$my_job = Start-Job -Name "remote job" -ScriptBlock {
$my_logfile = "c:\myfolder\mylog.txt"
$my_message = "I started"
$my_message >> $my_logfile
$my_message = "I terminated"
$my_message >> $my_logfile
}
}
#
Something must be wrong because I don’t see any log created on the target server and the code in the scriptblock is simply terminated.
How can create a job so that it can be execuded and terminated asynchronously?
How can I see the reasons becose the job fails?
Regards
marius