multi invoke-sqlcmd in foreach

  • Good morning all

    I'm looking to replace all these invoke-sqlcmd in one through a foreach loop

    Who has an idea 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_SQL" |export-csv -path "$path\SP_EQUITE_SANTE_CDC_SQL_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_Travel" |export-csv -path "$path\SP_EQUITE_SANTE_CDC_travel_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC2" |export-csv -path "$path SP_EQUITE_SANTE_CDC2_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC_3Contrats" |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_CDC4_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_CDC5_work" |export-csv -path "$path\SP_EQUITE_SANTE_CDC_work_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC6_Encaissements23" |export-csv -path "$path SP_EQUITE_SANTE_CDC_Encaissements23_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_EQUITE_SANTE_CDC7_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_like" |export-csv -path "$path\exec SP_EQUITE_like_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"
    Invoke-Sqlcmd -ServerInstance "$serverinstance" -database "Gestion_BO_Stats" -Query "exec SP_produit" |export-csv -path "$path\SP_produit_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv"

     

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

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

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