Skip to content

Instantly share code, notes, and snippets.

@miteshsureja
Created May 26, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miteshsureja/63700dd4868e7c0483a2209108a935d5 to your computer and use it in GitHub Desktop.
Save miteshsureja/63700dd4868e7c0483a2209108a935d5 to your computer and use it in GitHub Desktop.
Import-Csv and Export-Csv PowerShell cmdlets
#export data using Export-CSV cmdlet
Get-EventLog Application -Newest 100 | Export-Csv logs.csv
Get-Content logs.csv
#import CSV data using Import-CSV cmdlet
#specify path
$path = "C:\PowerShell\logs.csv"
#import csv file and specify specific columns you want to import using -Header
$file = Import-Csv $path -Delimiter ","
#$file
#loop all the rows in file
foreach ($row in $file)
{
#condition to read only Errors
if ($row.EntryType -like '*Error*')
{
Write-Host "---------------------------------------------"
Write-Host $row.EntryType
Write-Host $row.TimeGenerated
Write-Host $row.Message
Write-Host "---------------------------------------------"
}
}
@miteshsureja
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment