windowspowershellscriptingmalwareexecutionpolicy

PowerShell: Execution policy workarounds to run a script


Is there a workaround for execution policies?

PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> .\stock.ps1
.\stock.ps1 : File C:\Users\thufir\Desktop\stock.ps1 cannot be loaded because running scripts is disabled on this
system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\stock.ps1
+ ~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\thufir\Desktop>

I am just looking to find stock quotes with a script. Yes, you can sort of/kind of run a script with copy/paste, but...isn't there anything nicer?

Policy is as:

PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined


PS C:\Users\thufir\Desktop>

(Not my machine.)

I am looking for the inverse to this question.


Solution

  • To build off of Bill_Stewart's comment, create a shortcut with the following target and it will allow you to run a PowerShell script:

     C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file "\\Server\Path\to\script\script.ps1"
    

    If you want to run this command on a remote machine, you can can always do something like this after creating the above shortcut and storing it somewhere the remote machine can access on the network.

    Invoke-Command -computername Computer1 -Scriptblock { Start-process "\\Server\Path\to\shortcut\shortcut.lnk" }