I have a powershell line that works great:
Start-Job { plink.exe -telnet 000.000.000.000 -P 1000 > LogFile.txt }
Job runs as expected in the background, text file is created.
When I throw TimeStamp in there than run the job, Get-Job shows it completed, and the file is not created. Not sure if it makes the connection or not in this case.
Start-Job { plink.exe -telnet 000.000.000.000 -P 1000 | TimeStamp > LogFile.txt }
When I run the above without Start-Job and with TimeStamp it works fine. Obviously it is finishing the job at TimeStamp. Any ideas for a workaround or another way to get the timestamp in the log file. Running it as a job is the way i want to go mainly So I can stop it at a specific time, parse the logs than restart with a new file name. Here the rest of the script:
filter timestamp {"$(Get-Date -Format MM/dd/yyyy_HH:mm:ss) $_"}
Start-Job -Name Logging { c:\plink.exe -telnet 000.000.000.000 -P 10000 | TimeStamp
> c:\users\User\"LogFile_$(get-date -f MM-dd-yyyy).txt" }
[datetime]$JobEndTime = '23:50'
$AddDaysWhenInPast = 1
[datetime]$CurrentTime = Get-Date
If ($JobEndTime -lt $CurrentTime) { $JobEndTime =
$JobEndTime.AddDays($AddDaysWhenInPast) }
[int]$WaitSeconds = ( $JobEndTime - $CurrentTime ).TotalSeconds
#Debug
#write-Host $JobEndTime
#Write-Host $AddDaysWhenInPast
#Write-Host $CurrentTime
#Write-Host $WaitSeconds
#Write-Host $AddDaysWhenInPast
#Pause
Stop-Job logging
Set-Content -Path C:\users\User\"LogFile_$(get-date -f MM-dd-yyyy).txt" -Value (get-
content -Path C:\users\users\User\"LogFile_$(get-date -f MM-dd-yyyy).txt" | Where-
Object { $i % 2 -eq 0; $i++ })
Set-Content -Path C:\users\User\"LogFile_$(get-date -f MM-dd-yyyy).txt" -Value (get-
content -Path C:\users\User\"LogFile_$(get-date -f MM-dd-yyyy).txt" | Select-String -
Pattern '00000' -NotMatch)
(loops back to top)