Export-CSV with the path as a variable

  • Good morning all

    I'm looking to export the result of the execution of a stored procedure to a csv file

    except that I can't do an export-csv with a path created from a variable

    who can help me please

    $serverinstance='DBAOG_DATAWH\DWH'
    $database='Gestion_BO_Stats'
    $path='C:\TSQL\EDI\EDI_AOG\EDI SANTE\CDC Santé EQUITE\Resultat'
    get-childitem -path $path -include *.csv -recurse | remove-item
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Contrats" |export-csv -path $path + "\SP_EQUITE_SANTE_CDC_Contrats_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Bénéficiaires" |export-csv -path $path + "\SP_EQUITE_SANTE_CDC_Bénéficiaires_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Commisisons" |export-csv -path $path + "\SP_EQUITE_SANTE_CDC_Commisisons_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Encaissements" |export-csv -path $path + "\SP_EQUITE_SANTE_CDC_Encaissements_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"

     

    Attachments:
    You must be logged in to view attached files.
  • You can try

    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Contrats" |export-csv -path "$path\SP_EQUITE_SANTE_CDC_Contrats_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"

    as powershell variables are expanded when used between double qoutes

Viewing 2 posts - 1 through 1 (of 1 total)

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