I'm trying to figure out how to use a timer in Windows PowerShell. I want my script to run a command/task for a certain amount of time, stop the task, and then output the results to a txt file. Here is what I have so far:
$timer = [Diagnostics.Stopwatch]::StartNew()
while ($timer.elapsed.totalseconds -lt 10){
netstat 169.254.219.44
$timer.stop() |
Out-File $PSScriptroot\connections.txt
break
}
All the script does is run the command in the terminal until I press ctrl+c. Once I press ctrl+c it stops and then outputs the .txt file. But the .txt file is blank. I've spent way more time than I should've trying to figure this out. I'm new to Windows PowerShell and was just messing around to see what I could do. There's no real purpose for this script. It's just driving me nuts that I can't figure this out...
whileloop. that means your test will never trigger. [grin]