Powershell Scripts
-
Wednesday, February 27, 2008 1:28 PM
OK, I'm kinda getting hooked on the functionality of the PowerShell. I've been slowly converting all my old Korn Shell and CMD scripts over. Now I'm inside Visual Studio 2008 and I want to run a script, but because of the odd way that PowerShell has of parsing commands, you get the following error:
PowerShell "C:\Users\My User\script1.ps1"
The term 'C:\Users\My' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a nd try again.
Also, I've notice that I can't run SQL scripts either from inside the IDE. There must be some trick to forcing a command to run by right clicking the mouse (e.g. There used to be a 'Run' command associated with CMD files in database projects, where has this function gone?)
All Replies
-
Wednesday, February 27, 2008 5:48 PMDonald,
Thanks for your interest. I suggest you try the Powershell newgroup for this type of question:
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell
Hope this helps,
Steve - www.platinumbay.com -
Thursday, February 28, 2008 12:41 PM
Steve,
Please have the courtesy of reading the original post and having something useful to say before responding. I know exactly why PowerShell is issuing the error message, it requires a special syntax to distinguish between parsing commands line arguments and parsing the C# language constructs. What I'm missing is how Visual Studio can be configured to call out to the OS to execute these commands.
-
Thursday, February 28, 2008 1:34 PMDonald,
My apologies. I did in fact read your post, but somehow managed to glance over that all important detail.
You can run commands from inside of Visual Studio in two ways.
The first is through External Tools in the tools menu. You can set up commands and parameters to be run from menu items in the Tools menu.
The second is through pre and post build events for your projects.
Hope this helps,
Steve - www.platinumbay.com -
Friday, February 29, 2008 8:23 PM
In Visual Studio 2005 you had the ability, in database projects anyway, to right click in the 'Solution Explorer' and run a command shell script. What has happened to that function?
At the very least, I would like to be able to run command the command shell scripts that I find in the Solution Explorer. Ideally, I'd like to be able to run PowerShell scripts by a 'Right Click/Run' type of operation in the Solution Explorer. There are a lot of developer tasks that don't fit into the 'Pre' and 'Post' build events, such as rebuilding a database from a script or loading it with data. There must be an easier way to do this than jumpping out to a PowerShell command prompt each time I have an automated task to run.
-
Friday, February 29, 2008 8:39 PMDonald,
If you have PowerShell scripts in your project, you can right-click on one of them, choose "Open With...", then browse to and select powershell.exe. Once powershell.exe has been selected you may also click on the set as default button. This means that any time you open a powershell script in Visual Studio, it will be opened with PowerShell.
Hope this helps,
Steve - www.platinumbay.com -
Thursday, September 17, 2009 3:47 PMThis last suggestion by Steve is what I cannot get to work. By default, powershell_ise.exe is run and I cannot find the registry entry or whatever to consider modifying to regular powershell.exe and when I try to add powershell.exe, exactly as suggested, the command window flashes so quick with some error that I cannot read it so do not know why it is failing. If I do the same action, "run with Powershell" from Explorer, the script runs fine. I did find the VS2008 registry entry for the new "editor" but was not able to tweak to run like the explorer version. Ideas? Thanks, Dave
-
Thursday, September 17, 2009 4:09 PMAfter running this over and over again, I finally saw that Powershell was complaining about the script path argument passed to it from VS2008 which obviously was not quoted and since it had a space in the VS2008 path, was not finding the script! This was DOnald's original complaint. How can VS2008 be taught to "properly" call powershell by quoting the script path? I tried adding a quoted %1 argument etc. to the new registry key same as the explorer open action and that caused the ps1 key's "Windows Powershell" subkey to actually be deleted by VS2008 and not even show in the "open with" menu anymore. The HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Default Editors\ps1 key remained. I tried this a couple times to make sure I was not seeing things! I don't want to run the _ise version, I want, at least as a choice, to run the regular powershell version but since VS2008 puts a project into a default path that has a space in the path, this mechanism just does not work and is apparently a bug in VS2008!
-
Monday, February 14, 2011 1:18 AM
Donald,
Thanks for your interest. I suggest you try the Powershell newgroup for this type of question:
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell
Hope this helps,
Steve - www.platinumbay.com
Your info is very helpful to my study, I'm still studying it.

