Created
May 26, 2018 11:46
-
-
Save miteshsureja/63700dd4868e7c0483a2209108a935d5 to your computer and use it in GitHub Desktop.
Import-Csv and Export-Csv PowerShell cmdlets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 "---------------------------------------------" | |
} | |
} |
Author
miteshsureja
commented
May 26, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment