c# - Powershell Get-ExecutionPolicy returns different values -


depending on method used execution policy setting powershell, 2 different values.

if run get-executionpolicy in powershell prompt, 'unrestricted'.

if use following code, 'restricted'.

using (var runspace = runspacefactory.createrunspace()) {     runspace.open();      var pipeline = runspace.createpipeline();     pipeline.commands.addscript("get-executionpolicy");      foreach (var result in pipeline.invoke())     {         var restriction = ((executionpolicy)result.baseobject);         break;     } } 

again, 'restricted' following code:

using (var invoker = new runspaceinvoke()) {     foreach (var result in invoker.invoke("get-executionpolicy"))     {         var restriction = ((executionpolicy)result.baseobject);         break;     } } 

i checked in registry here: hkey_local_machine\software\microsoft\powershell\1\shellids\microsoft.powershell\executionpolicy , there says unrestricted.

any idea why different result? code incorrect perhaps?

are implementing custom host? if so, default execution policy restricted , need set host (under shellids).

either way, should able execute command first in code override setting:

set-executionpolicy remotesigned -scope process 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -