Search code examples
powershellwindow

Powershell script on network drive still giving security prompt even after running Unblock-File


I am trying to run a Powershell Cmdlet that I wrote.

It is stored on a network drive mapped to Z:\....

I have launched Powershell in administrator mode and set the execution policy to Unrestricted.

I have run Unblock-File on my Cmdlet, and every script that it calls.

I am calling my Cmdlet either with its absolute path, or with a relative path beginning with .\.

But still, tab completion is not working for my Cmdlet's parameters, and I still get this security warning:

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script
can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to
allow the script to run without this warning message. Do you want to run <file-name>?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

What am I doing wrong?


Solution

  • The answer, in my case, is that Windows was configured to regard the network drive as a location on the public internet.

    The solution was to launch the Internet Options control panel, navigate to the Security tab, and add the network share where my scripts were located (eg, \\networkshare) to the Local intranet security zone.

    Afterwards, the tab completion worked correctly with my Cmdlet's parameters, and the script could execute without any security warning.