Search code examples
powershellexecution

How to allow one user to one run one powershell script on his computer


I have a script I've written on my computer and need to make it available to another person. Since the other person has only very basic knowledge of computer usage, he is not an administrator on his computer (and he doesn't need to be).

Problem is, that of course the default execution policy is Restricted which prevents him to run scripts. I don't want to change it to Unrestricted permanently as that would pose a security risk and he can't change the policy every time he needs to run the script. Honestly, it would be far too complicated for him.

Is there some way around it?

I don't want to run the script for him every month or come to his office to set the execution policy and then set it back again. Can a self-signed certificate generated on my computer be used for that? If so, how exactly?

PS. We don't have AD CS in our organisation - 6 servers and 300 client stations is not such a huge infrastructure to create one.


Solution

  • The easiest workaround is to just place a shortcut on the users desktop that launches PowerShell with the -ExecutionPolicy Bypass command line switch:

    • Shortcut target:
      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\path\to\script.ps1

    This way the execution policy is overridden only when the user launches this particular script through this particular shortcut.