Solution to your problem :
For some reason, account on which you run VS on and on which VS hosts PowerShell has restricted ExecutionPolicy (you can type Get-ExecutionPolicy , select the text and hit CTRL+F8 and should see Restricted as the answer).
So the solution is simple (should be): override the settings and set it to RemoteSigned with this command :
select the text, hit CTRL+F8. Now hitting F5 should make your PS behave.
(Alternatively Unrestricted is also viable option, but this is considered unsafe. More on this here : http://technet.microsoft.com/en-us/library/ee176961.aspx)
More on the topic :
I wanted to create some PowerShell script and I thought there has to be something better than PowerShell ISE (sry, I am just too used to VS and debugger and all that goodness I have at my disposal) so I discovered this wonderful plugin for VS 2012 – PowerShell Tools for Visual Studio – http://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597 and all worked as expected, until (as far as I remember) I restarted OS and had this strange error in VS in my output window :
Error: File C:\users\your_name\documents\visual studio 2012\Projects\PowerShell Script Project1\PowerShell Script Project1\Script.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/
- Writing some text in the .ps1 file in VS and selecting some code and right click reveals Execute selection option that is able to run your code event if it fails running it F5,
- Adam downloaded in his spare time NuGet sources and it looks like : “NuGet sets the process scoped execution policy to RemoteSigned when it is initialized. “
So next logical step would be to try to run Set-ExecutionPolicy from VS to set it for account that VS is using to run PowerShell. And it looks like it is working.
Enjoy guys and thanks Adam for your plugin and your time.