0
votes

I have a powershell script that exports the results of an SQL statement to CSV.

Export Command in Powershell

$DataSet.Tables[0] | Export-Csv $extractFile -NoTypeInformation

Script is called ExportToCsv.ps1

I call it via command prompt, works fine and saves the file.

I run the script via powershell GUI, works fine and saves file.

Create an External Tool in SSMS and it looks like it runs (window flashed up and closes) but nothing is saved.

External Tool Settings:

Command: %windir%\System32\WindowsPowerShell\V1.0\powershell.exe

Arguments: -File C:\ExportToCSV.ps1 $(CurText)

I ticked the "prompt for arguments" option to see what it was actually doing and its this:

C:\windows\System32\WindowsPowerShell\V1.0\powershell.exe -File C:\ExportToCSV.ps1 "select 1,2,3"

I copy and run that full command into a cmd and it works fine.

Any idea why this is not doing anything via SSMS?

1

1 Answers

0
votes

Forget it, found the issue by ticking "Use output window" in SSMS external tools. It says why:

"ExportToCSV.ps1 cannot be loaded because the execution of scripts is disabled on this system."