I was trying to throw together a quick script earlier to watch the resource use of some IE instances on a machine. I needed the script to keep logging until I told it to stop. Rather than just interrupt it, I had it watching for a flag file to be created to tell it to stop.
My issue is how to get the objects I'm generating into a CSV file neatly. The existing script generates a new header in the CSV on each loop. I can sort the file and cut these out after the fact but there must be a way to do what I'm wanting without having to do that.
Ideally, I'd like to dump process objects into the pipeline repeatedly and then on exiting the loop, send them off to convertto-csv. The method as to how to do this evades me at present... Any ideas? Thanks!
Write-Host "*** Started ***"
$start = [DateTime]::Now
do {
$timeSpan = [DateTime]::Now - $start
Get-Process -Name iexplore |
Select-Object -Property @{N="Time (secs)";E={$timeSpan.TotalSeconds -as [int]}},
@{N="Process ID";E={$_.ID}},
@{N="Virtual Memory (MB)";E={$_.VirtualMemorySize / 1MB -as [int]}},
@{N="Handle Count";E={$_.Handles}},
@{N="Thread Count";E={$_.Threads.Count}} |
ConvertTo-Csv -NoTypeInformation |
Out-File "c:\IEs.csv" -Append -Encoding ASCII
Start-Sleep -Seconds 3
} until ( Test-Path c:\Flag.txt )
Write-Host "*** Finished ***"