Do some of you know how to add headers to an out-file csv? I was looking on many other examples but don't find one that can help me.
Right now my output looks like this:
Name : Steve
Adress: Berlin
Age: 21
And more....
but I would like to get it like this
Name Adress Age
---- ------- ---
Steve Berlin 21
[xml]$config = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Config.xml'
[xml]$blacklist = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Blacklist.xml'
#Names to filter
$BLN = $blacklist.Names
#Import Path
$info = Import-Csv $config.config.path.input -Delimiter ';'
$info | Format-Table
#from which month
#$dateCutoff = get-date "02.2020" -Format "MM.yyyy"
$dateCutoff = $config.config.date
$result = foreach($i in $info){
if(-Not($BLN -contains $i.SCAN_USER)){
$entryDate = Get-Date $i.SCAN_DATE -Format "MM.yyyy"
if($entryDate -eq $dateCutoff){
$i
}
}
$result | Out-File $config.config.path.output
Write-Host $i
$config.config.path.output + "\" + $info | Out-File -Append $config.config.path.output
}
Using Export-CSV:
To export CSV documents you shouldn't use
Out-File
. You should useExport-CSV
:Using Out-File: