Powershell : convert a file to UTF-8 without BOM + LF

  • Hi,
    I  have an issue with files conversion in powershell.
    1. I try a bcp command to export a file (with a format file for convenience), Format UTF8 + LF.
    2. I convert it in UTF8 without BOM (but my LF begins CRLF)
    3. I convert my CRLF to LF (but I lose my UTF8 without BOM conversion...)

    Do you have any idea ?

    Thanx a lot!!

    The sourcecode :
    # Creation Fichier BCP
    $database = "Mydatabase"
    $schema = "dbo"
    $table = "t_TSCOM_Dashboard_hebdo"
    $fichierBCP = "K:\saved\output\t_TSCOM_Dashboard_hebdo.bcp"
    $fichierFormat = "K:\saved\FORMAT\t_TSCOM_Dashboard_hebdo_6.fmt"
    $loginUser = "MeMyAndMyself"
    $passwordUser = "XXXXXXXXXXXXX"
    $server = "MyServer"

    $bcp = "bcp $($database).$($schema).$($table) out $fichierBCP -f $fichierFormat -U $loginUser -P $passwordUser -S $server"
    Invoke-Expression $bcp

    ## Affectation des fichiers
    $fichierBCP_Contenu = Get-Content $fichierBCP
    $fichierUTF8sansBOM = "K:\saved\output\MyFile_SLA_WEEK_HISTO_CRLF.DEL"
    $fichierDEL = "K:\saved\output\MyFile_SLA_WEEK_HISTO.DEL"

    ## Conversion en UTF8 sans BOM (OK mais LF > CRLF)
    [System.IO.File]::WriteAllLines($fichierUTF8sansBOM, $fichierBCP_Contenu)

    ## conversion CRLF > LF (mais on perd conversion UTF8-sansBOM)
    (Get-Content $fichierUTF8sansBOM) -join "`n" | Out-File -Encoding UTF8 $fichierDEL

    Johan Jezequel
    ** Sorry for my english, I promess you I do my best **

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply