powershell - Content not deleting properly -


i writing script display output of get-eventlog csv

$file_name = "$env:tmp\event_logs.csv"  if(test-path $file_name){ clear-content $file_name } $event_logs_content | convertto-csv | set-content $file_name start $file_name 

but when executed second time, results first time still exist in file , third time execution first 2 attempts output still exist in file , on..

i have tried deleting ~"files" in tmp path of no use, please suggest

this should work done:

$file_name = "$env:tmp\event_logs.csv"  if(test-path $file_name){ remove-item $file_name -force } $event_logs_content | convertto-csv | out-file $file_name -force 

assuming $event_logs_content having proper values want set in file. because not seeing event logs retrieval code.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -