I have a Windows powershell script that works fine in the interactive editor. The script is a simple one line sql cmd:

sqlcmd -S servername -d dbname -E -W -w 999 -s "," -Q "SELECT select col1,col2,'','','','','','','','','','','','','','','','','','','','','','','','','' From Table" -o "C:\sqlcmd.csv"

When I enter that at the powershell command prompt it works fine. I save it in a ps1 file and try to run it from the cmd prompt by typing .\filename.ps1, it opens it in Notepad, and does not execute it.

I then try to run it as a command like this:

powershell sqlcmd -S servername -d dbname -E -W -w 999 -s "," -Q "SELECT select col1,col2,'','','','','','','','','','','','','','','','','','','','','','','','','' From Table" -o "C:\sqlcmd.csv"

And that says "-s missing parameter...".

Any suggestions on getting this to run right? I read something somewhere about Windows execution policy and was wondering if it was something like that.

Operating System is Windows XP, SP2.

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

You can run the Powershell script from the command prompt like this:

powershell -command "& .\filename.ps1"

You may need to change your execution policy to run Powershell scripts.

powershell -command "Set-ExecutionPolicy Unrestricted"
link|improve this answer
feedback

I would not use PowerShell for this. It serves no purpose doing so other than forcing PowerShell to load, parse the line for variables, and then call the external program. Save it to a .cmd file and use it as a batch program because that's what it really is.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.