Powershell cannot read CSV - Export is from Oracle

André Borgeld 431 Reputation points
2020-12-03T11:56:27.387+00:00

As people maybe have seen I'm busy with adding a User Principle Name to a CSV. Now with some help that code works.
Only after debugging I discovered the issue. I don't get data from the CSV I import.

When i try the easiest thing, my variable stays empty

$csvfile = Import-CSV -Path C:\Temp\eport.csv

Foreach ($line in $csvfile) {

Write-Host $line.EMAIL  

}

My import-csv is from an Oracle DB export and looks like this, I trimmed spaces
EMAIL;Username;
a.borgeld@Karima ben .com;ABORGELD;
a.borgeld@Karima ben .com;ABORGELD;

Does anybody have experience with CVS's from a database that you can't read? Of course when i open the notepad then the data is there

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 95,496 Reputation points MVP
    2020-12-03T12:10:17.277+00:00

    Adding the -Delimiter ";" should help:

    $csvfile = Import-Csv -Path C:\Temp\export.csv -Delimiter ";"  
    foreach ($line in $csvfile)  
        {  
            Write-Output $line.EMAIL  
        }  
    

    My CSV file looks like this:
    EMAIL;Username;
    a.borgeld@Karima ben .com;ABORGELD;
    test@Anonymous .bar;TEST

    Output of the script is the email of every line:
    a.borgeld@Karima ben .com
    test@Anonymous .bar

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. André Borgeld 431 Reputation points
    2020-12-03T12:36:45.197+00:00

    Oh my @Andreas Baumgarten sometimes life can be so easy.
    Thanks for getting me out of that black whole. The whole script will work now.
    You've got to deal with different outputs.

    0 comments No comments