OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

"Run with PowerShell" gives execution policy error but running directly in PowerShell window does not

  • Thread starter Thread starter charlesz
  • Start date Start date
C

charlesz

Guest
I have a simple .ps1 script that basically just creates a directory. When I right-click on the script in Windows Explorer and select "Run with PowerShell", it gives the following error message:

Get-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Unrestricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".

(I recorded my screen and typed all those above, as the window only flashed quickly. Also, if I run "powershell -NoExit C:\path\to\script.ps1", there is no error.

Interestingly, folder is still created.

However, if I open PowerShell myself and run the script like .\script.ps1, it does not have any error.

Here is the output of Get-ExecutionPolicy -List:

Code:
        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy    Unrestricted
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    Unrestricted

I think "Run with PowerShell" is trying to do something (like setting execution policy) before running the script, but I cannot see the full command that it invoked, and I don't know what scope it is trying to set execution policy for. Also, which of the above is more specific scope than which of the others?

I also don't have admin access to override this context menu item either. How should I get a clean execution?

Might be different from Unable to execute PowerShell Script using 'Run with Powershell' option as it seems my execution actually succeeded.

I expect to run the script cleanly from Windows Explorer, i.e., there should be no error outputs.
<p>I have a simple <code>.ps1</code> script that basically just creates a directory. When I right-click on the script in Windows Explorer and select "Run with PowerShell", it gives the following error message:</p>
<blockquote>
<p>Get-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Unrestricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".</p>
</blockquote>
<p>(I recorded my screen and typed all those above, as the window only flashed quickly. Also, if I run "powershell -NoExit C:\path\to\script.ps1", there is no error.</p>
<p>Interestingly, folder is still created.</p>
<p>However, if I open PowerShell myself and run the script like <code>.\script.ps1</code>, it does not have any error.</p>
<p>Here is the output of <code>Get-ExecutionPolicy -List</code>:</p>
<pre><code> Scope ExecutionPolicy
----- ---------------
MachinePolicy Unrestricted
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted
</code></pre>
<p>I think "Run with PowerShell" is trying to do something (like setting execution policy) before running the script, but I cannot see the full command that it invoked, and I don't know what scope it is trying to set execution policy for. Also, which of the above is more specific scope than which of the others?</p>
<p>I also don't have admin access to override this context menu item either. How should I get a clean execution?</p>
<p>Might be different from <a href="https://stackoverflow.com/questions...shell-script-using-run-with-powershell-option">Unable to execute PowerShell Script using &#39;Run with Powershell&#39; option</a> as it seems my execution actually succeeded.</p>
<p>I expect to run the script cleanly from Windows Explorer, i.e., there should be no error outputs.</p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top