Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to CSV in 1 step

Status
Not open for further replies.
May 23, 2001
300
0
0
US
There has to be a way to get this to export 1 csv instead of writing to result.csv then get result.csv and clean it then save as result_parsed.csv.

This gets the data I need:
Code:
$cl = $ComputerList = get-content c:\list.txt
$a = (Get-Date).adddays(-1)
Get-EventLog -ComputerName $cl -LogName system -After $a -Source print | select machinename,timegenerated,entrytype,message | Export-Csv c:\result.csv

After the above file is saved this process below cleans it up.
Code:
$original_file = 'c:\result.csv'
$destination_file =  'c:\result_parsed.csv'
(Get-Content $original_file) | Foreach-Object {
    $_ -replace '"', '' `
       -replace '#TYPE Selected.System.Diagnostics.EventLogEntry', '' `
       -replace 'MachineName', '' `
       -replace 'TimeGenerated', '' `
       -replace 'EntryType', '' `
       -replace 'Message', '' `
       -replace ', ', ',' `
       -replace ' owned by ', ',' `
       -replace ' was printed on ', ',' `
       -replace '.  Size in bytes: ', ',' `
       -replace '; pages printed: ', ',' `
    } | Set-Content $destination_file

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top