I have a powershell script that will run a query and export the results to Excel. I want to hook this into SQL Studio Management Studio (2008)'s external tools. SSMS will not allow powershell scripts so I am using a batch file to get it started.
In the external tools section you can specify some predefined arguments. The argument that I want is called "current text". This argument passes whatever is highlighted to the tool (batch file). My batch file then passes that argument on to a powershell script.
The problem is that if the user has a query that spans multiple lines highlighted then the powershell script fails because of the linebreaks. It seems it would be relatively easy to strip them out, or better yet, replace them with a space?
Here is my batch file:
echo %~1
call powershell ^& 'c:\temp\ExportSQL.ps1' -query "%~1"
My question is how can I replace newlines and carriage returns from %1 with a space before passing it to the powershell script? TIA.