ATur
ATur

Reputation: 157

Security Warning when running scripts - Unblock-File not unblocking file

I suddenly started to recceive this warning when running any script on my computer:

Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer...

Screenshot:

Powershell Security Warning

The files are not blocked.

I have

Also tried to remove streams with Powershell:

Remove-Item -Path \\Path\Script.ps1 -Stream Zone.Identifier

Of course without success as there are no streams.

Execution policy is Unrestricted.

When I run Set-ExecutionPolicy Bypass it works without warning. It should, however, also work when it's unrestricted.

I honestly don't know what's going on.

Upvotes: 7

Views: 25834

Answers (5)

js2010
js2010

Reputation: 27423

This is the only thing that worked for me, adding the exact hostname of the share:

reg add "hkcu\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\school.edu\mdt.sys" /f /v * /t REG_DWORD /d 1

And with execution policy unrestricted, I was running:

powershell -executionpolicy bypass -file script.ps1

Upvotes: 0

lauxjpn
lauxjpn

Reputation: 5254

The correct registry keys, name and value, to treat all local sites as part of the intranet zone, are:

Keys:

HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
HKCU\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap

Name:  IntranetName
Type:  DWORD
Value: 1

You can set this via PowerShell for the local machine (in an elevated prompt) like this:

Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap" -Name "IntranetName" -Type DWord -Value 1

See Intranet Sites: Include all local (intranet) sites not listed in other zones for more information about the group policy.

Upvotes: 1

Backlash52
Backlash52

Reputation: 126

After searching i found someone with similar issues and it was explained that Classic UNC paths will work without prompting to unblock the file:

\\Servername\Path...

However FQDN paths are not seen as safe by default and will prompt:

\\Servername.foo.local\Path...

My own testing confirms this to be correct as removing the .foo.local from the path causes the Unblock-File prompts to stop.

Upvotes: 11

DisplayName
DisplayName

Reputation: 1016

LGPE > gpedit.msc

Computer Configuration > Administrative Templates, > Windows Components, > Internet Explorer>expand Internet Control Panel. Security Page > Intranet Sites: Include all local (intranet) sites not listed in other zones, and then click Properties. Click Enabled.

Turn on automatic detection of the intranet, and then click Properties. Click Disabled, and then click OK.

or registry

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\"UNCAsIntranet" = "0"

Upvotes: 0

A Nikhade
A Nikhade

Reputation: 17

PS doesnot allow Scripts to run on system ENV by default. you need to set the policy to unrestricted or remote signed Use: Set-ExecutionPolicy Remotesigned OR Set-ExecutionPolicy Unrestricted

Open the PS console and type this and press enter and then try running your script.

Upvotes: -3

Related Questions