I want to read a csv file in 2 columns that when i will open my excel it will shows the informations of my CSV file displayed in 2 columns.
Actually, i only display in one column with the Following code :
Function Read-File {
Param([string]$file, [string]$head)
if (Test-Path $file) {
Write-Verbose "$file exists, importing list."
$data = Import-Csv -Path $file
$s = @()
if ($data.$head) {
foreach ($device in $data) {
try {
$s += $device.$head
Write-Verbose -Message "$device.$head"
} catch {
Write-Error -Message "Failed to add $device to list."
}
}
} else {
Write-Error -Message "No such column, $head, in CSV file $file."
}
return $s
}
}
$list = Read-File $file $fileColumn
So now i want to do it but in 2 columns , i'm a beginner in PowerShell so i would apreciate some help :) thank you
this is my CSV file :
Asset Number, Serial Number
cd5013172cffd6a317bd2a6003414c1,N5WWGGNL
8df47f5b1f1fcda12ed9d390c1c55feaab8,SN65AGGNL
dc0d1aaba9d55ee8992c657,B2NGAA3501119
i am only trying to display thoses both ( asset number and serial number) on 2 columns on my excel , dont worry thoses informations are not sensitive at all so its ok :)
$nullvalue or empty string as the-Fileargument to yourReadFilefunction. You can detect this problem earlier by declaring your-Fileparameter to only accept non-empty input:[ValidateNotNullOrEmpty()][string]$file