Output of reception results to a file
how can I output the receive-result output to a file?
I tried this but it doesn't work:
$log = "C:\springfield\citrix\CitrixAutomation.log"
Get-Job | Receive-Job | Out-File $log
I also tried to store the output Get-Job | Receive-Job
in a variable, but it doesn't work.
$log = "C:\springfield\citrix\CitrixAutomation.log"
$getjobarr = @()
Function LogWrite
{
Param ([array]$logstring)
$logstring | Out-File $log -Append
}
$getjobarr += Get-Job | Receive-Job
LogWrite $getjobarr
I think Get-Job
u Receive-Job
can only output to the console , so how can I achieve it?
thanks for the help
source to share
The "exit" of the job can be redirected to a file, for example:
PS> Start-Job {Get-ChildItem C:\users\keith}
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
2 Job2 BackgroundJob Running True localhost Get-ChildItem C:\users...
PS> Receive-Job -id 2 | Out-File job.log
PS> gc .\job.log
Directory: C:\users\keith
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/21/2014 8:24 PM <DIR> .ssh
d---- 9/9/2014 10:00 PM <DIR> Bin
d-r-- 9/11/2014 9:20 PM <DIR> Contacts
d-r-- 9/11/2014 9:20 PM <DIR> Desktop
If everything you do in the job writes to the host, then yes, you will be hosed. If you are in control, use write-output instead of write-host. Also, make sure you wait for each job to complete before receiving its output, if you cannot sit in a loop until the job status changes to Completed or Failed. You can use Wait-Job to wait for a job to complete before requesting its output.
source to share