I need to create powershell script on SQL server A.
The script will connect to a remote SQL server B and run a query there and then export it as a csv file on a network directory.
I know I can use something like this:
Invoke-Sqlcmd -Query $SqlQuery -ServerInstance $SourceServer |
Export-Csv -Path "$destOutputPath\myfile.dat" -NoTypeInformation -Encoding UTF8
But I also want to create a log file that log the process of this powershell script, how can I do it?
Thanks