PowerShell – Saving SQL query results to a CSV file

With PowerShell, you can execute a SQL query with Invoke-Sqlcmd. If you want to save the query results to a CSV file, you can use Export-Csv. Here’s an example: If Invoke-SqlCmd is missing, install the SqlServer module If it’s complaining about not having Invoke-SqlCmd available, you will need to install the SQL Server PowerShell module. … Read more