February 24, 2020 at 11:01 am
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"
February 24, 2020 at 12:35 pm
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