Bonjour bonjour
Je débute en PowerShell et je suis perplexe... En effet, mon code a pour but d’exécuter du SQL, puis d'interroger une table SQL Server et en générer le résultat dans un fichier CSV.
Quand je fais tout ça sans fonction, sans fioriture, ça fonctionne. J'ai ensuite essayé de rajouter des fonctions pour que ce soit plus lisible et y rajouter des potentielles gestion d'erreur.
Je vous mets mon code :
Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 function ExportCsv{ $SQLCommand = New-Object System.Data.SqlClient.SqlCommand $sqlCommand.CommandTimeout = 100 $SQLCommand.CommandText = "select * from matable;" $SQLCommand.Connection = $SQLConnection $SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SQLCommand $SQLDataset = New-Object System.Data.DataSet $SqlAdapter.fill($SQLDataset,'export') >$null| out-null $rowCount = $SqlAdapter.Fill($SQLDataset) #$SQLConnection.close() if($rowCount -gt 0) { $SQLDataset.Tables['export'] | Export-Csv -Path $extractFile -notypeinformation -Debub -Append } else { [System.Windows.Forms.MessageBox]::Show("perdu:") Write-Error "No data to display" } } ExportCsv
Quand j'exécute mon code via PowerShell ISE, dans la sortie de script, j'ai toutes mes données qui s'affichent, pas contre le fichier CSV n'est jamais crée... J'ai testé ma variable $extractFile elle fonctionne comme il faut...
Alors du coup, je ne comprends pas, pourquoi mon fichier csv ne se génère pas... Je suis perdu
Partager