Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - Running PowerShell from Post-Build event ignoring ExecutionPolicy


 
 
01-21-2009   #1 (permalink)
Ann Brady


 

Running PowerShell from Post-Build event ignoring ExecutionPolicy

I have my ExecutionPolicy set to Unrestricted. I can verify this in the
registry at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell . I can verify this by opening PowerShell and asking Get-ExecutionPolicy.

However, when I run a powershell command from a Post-Build event, either
from MSBuild or Visual Studio 2008 I get the error "cannot be loaded because
the execution of scripts is disabled on this system. Please see "get-help
about_signing" for more details."

If I run the same command directly from PowerShell there is no error.

I had a WindowsPowerShell profile, I removed it. I had the same error from
MSbuild and Visual Studio on loading my profile as running the post-build
command. Again, PowerShell (and my profile) load correctly with the correct
ExecutionPolicy level from outside MSBuild\Visual Studio.

I have uninstalled and reinstalled .NET, Visual Studio, SP1 for .NET and
Visual Studio and PowerShell 1.0. I am on windows server 2003 R2 x64 sp2.



Other developers do not have a problem, there is clearly something wrong
with my environment but I don't know where to look next.

The command is:
set ProjectSource=$(ProjectDir)
set ScriptOutput=$(TargetDir)CreateScript.sql
powershell.exe -command "$(projectDir)CompileCreateDatabase.ps1"
$env:ProjectSource $env:ScriptOutput

Any ideas are appreciated.
My System SpecsSystem Spec
01-21-2009   #2 (permalink)
Shay Levy [MVP]


 

Re: Running PowerShell from Post-Build event ignoring ExecutionPolicy

Hello Ann,

VS is probably launching the x64 version of PowerShell. x64 machines have
two PowerShell shortcuts, launch the x64 console and set the execution policy.
If you examine the property page for each shortcut you'll see the difference:

Windows PowerShell(32).lnk (x32) - %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Windows PowerShell.lnk (x64) - %SystemRoot%\sysWOW64\WindowsPowerShell\v1.0\powershell.exe

They also read/write to different sections in the registry.


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar


AB> I have my ExecutionPolicy set to Unrestricted. I can verify this in
AB> the registry at
AB> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsof
AB> t.PowerShell . I can verify this by opening PowerShell and asking
AB> Get-ExecutionPolicy.
AB>
AB> However, when I run a powershell command from a Post-Build event,
AB> either from MSBuild or Visual Studio 2008 I get the error "cannot be
AB> loaded because the execution of scripts is disabled on this system.
AB> Please see "get-help about_signing" for more details."
AB>
AB> If I run the same command directly from PowerShell there is no
AB> error.
AB>
AB> I had a WindowsPowerShell profile, I removed it. I had the same
AB> error from MSbuild and Visual Studio on loading my profile as
AB> running the post-build command. Again, PowerShell (and my profile)
AB> load correctly with the correct ExecutionPolicy level from outside
AB> MSBuild\Visual Studio.
AB>
AB> I have uninstalled and reinstalled .NET, Visual Studio, SP1 for .NET
AB> and Visual Studio and PowerShell 1.0. I am on windows server 2003
AB> R2 x64 sp2.
AB>
AB> Other developers do not have a problem, there is clearly something
AB> wrong with my environment but I don't know where to look next.
AB>
AB> The command is:
AB> set ProjectSource=$(ProjectDir)
AB> set ScriptOutput=$(TargetDir)CreateScript.sql
AB> powershell.exe -command "$(projectDir)CompileCreateDatabase.ps1"
AB> $env:ProjectSource $env:ScriptOutput
AB> Any ideas are appreciated.
AB>


My System SpecsSystem Spec
01-22-2009   #3 (permalink)
Ann Brady


 

Re: Running PowerShell from Post-Build event ignoring ExecutionPol

Shay,

That was exactly correct. I didn't realize I had to set the ExecutionPolicy
level for each.

Thanks.



"Shay Levy [MVP]" wrote:
Quote:

> Hello Ann,
>
> VS is probably launching the x64 version of PowerShell. x64 machines have
> two PowerShell shortcuts, launch the x64 console and set the execution policy.
> If you examine the property page for each shortcut you'll see the difference:
>
> Windows PowerShell(32).lnk (x32) - %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
> Windows PowerShell.lnk (x64) - %SystemRoot%\sysWOW64\WindowsPowerShell\v1.0\powershell.exe
>
> They also read/write to different sections in the registry.
>
My System SpecsSystem Spec
 

Running PowerShell from Post-Build event ignoring ExecutionPolicy problems?



Thread Tools


Similar topics to: Running PowerShell from Post-Build event ignoring ExecutionPolicy
Thread Forum
wcf service - publish as webservice post build .NET General
PowerShell, TFS, and Windows 7: ExecutionPolicy PowerShell
Powershell for Longhorn Build Build 6001 PowerShell
Event Viewer issue-where to post? Vista General
After IAudioClient::SetEvent the event is never set (Vista build 5 Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50