I'm trying to run a function in the background. This function needs to wait a period of time always. I've tried to solve the problem with start-job. But without success (the logs are empty).
My Function
Start-Job { a1 }
function a1()
{
$timer = [diagnostics.stopwatch]::startnew()
while ($timer.elapsed.totalseconds -lt 30)
{
writelog "TESTTESTTEST" $timer.elapsed.totalseconds
start-sleep -seconds 5
}
$timer.stop()
}
The log
function writelog([string]$func, [string] $Message, [string] $Value)
{
$loggingpath = $LogPath+(Get-Date -displayhint date -Format yyyyMMdd)+".txt"
Add-Content -Path $loggingpath -Value (" ")
Add-Content -Path $loggingpath -Value ("Date:" + (Get-Date))
Add-Content -Path $loggingpath -Value ("Function:" + ($func))
}
If I run the code with out start-job everything is working fine!