![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| | |||||||
| |
| 01-21-2009 | #1 (permalink) |
| | 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 Specs |
| 01-21-2009 | #2 (permalink) |
| | 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 Specs |
| 01-22-2009 | #3 (permalink) |
| | 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 Specs |
| 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 | |||