A short instruction how to export data from a table in SQL server to a CSV file with Powershell module DBATool and the command Invoke-DbaQuery.
A few examples with a query or procedure:
##Basic query example##
$query = "select top 100 * from Customer"
Invoke-DbaQuery -SqlInstance "localhost" -Database TestDB -CommandType Text -Query $query | Export-Csv -Path "C:\Temp\ExportData\Export_SqlServer.csv" `
-Delimiter ";" -NoTypeInformation
##Procedure exempel##
Invoke-DbaQuery -SqlInstance "localhost" -Database TestDB -CommandType StoredProcedure -Query 'dbo.usp_getCustomer' `
-SqlParameter @{ Name = "Roy" } | Export-Csv -Path "C:\Temp\ExportData\Export_SqlServerProcedure.csv" `
-Delimiter ";" -NoTypeInformation