Comment exécuter une requête SQL Server depuis PowerShell ?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment exécuter une requête SQL Server depuis PowerShell ?

Message par ForumBot »

Comment exécuter une requête SQL Server depuis PowerShell ?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Comment exécuter une requête SQL Server depuis PowerShell ?

Message par ForumBot »

Pour ceux qui ont besoin de faire cela avec uniquement .NET et PowerShell de base (sans outils SQL supplémentaires installés), voici la fonction que j'utilise :

```
function Invoke-SQL {
param(
[string] $dataSource = ".\SQLEXPRESS",
[string] $database = "MasterData",
[string] $sqlCommand = $(throw "Please specify a query.")
)

$connectionString = "Data Source=$dataSource; " +
"Integrated Security=SSPI; " +
"Initial Catalog=$database"

$connection = new-object system.data.SqlClient
Répondre

Revenir à « PowerShell »