I am trying to dump a lot of data into a file but if it takes too long I want to come out of the dump. Is there a way to do this in PowerShell? I tried the below but noticed that the logic is incorrect and will not do what I need.
$time = get-date
do
{
dir c:\ -Recurse | Set-Content .\outtext.txt
}
while ((Get-Date).AddSeconds(5) -le $time)