Shortcut to powershell 'Run as admin' not working on network drive

Ingrid 61 Reputation points
2022-07-07T10:03:21.193+00:00

I have created a Powershell script that I want to share with my colleagues who have admin accounts.

It needs to be run as admin, so I created a shortcut and enabled the 'Run as Administrator' (using the powershell -f prefix in the path).
From the c drive it is working fine, but when I copy the script to a network drive and create a new shortcut on the network drive, the script is not working.
No error, but it just opens for a second and then closes.

Any idea how I can fix this?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-07-07T23:13:46.333+00:00

    Add the -noexit switch to the arguments. That will keep the window open so that you can see the error. It's probably your execution policy.

    https://www.sqlshack.com/choosing-and-setting-a-powershell-execution-policy/

    Try

    Powershell.exe -noexit -executionpolicy unrestricted -file \\server\share\script.ps1   
    
    0 comments No comments

  2. Limitless Technology 39,921 Reputation points
    2022-07-13T07:55:15.267+00:00

    Hello Ingrid,

    This is a common issue, as running from network location requires a different unreactive session and thus a different execution policy. In this case, the users will receive an error that states that the Source is not trusted, then the program stops.

    An option to fix this would be to set the policy as Unrestricted on the user computer before trying to execute the Script on the network share:

    1. Select Start > All Programs > Windows PowerShell version > Windows PowerShell.
    2. Type Set-ExecutionPolicy RemoteSigned to set the policy to RemoteSigned.
    3. Type Set-ExecutionPolicy Unrestricted to set the policy to Unrestricted.
    4. Type Get-ExecutionPolicy to verify the current settings for the execution policy.
    5. Type Exit.

    ------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.