Ignore 'Security Warning' running script from command line

SecurityPowershell

Security Problem Overview


I am trying to execute a script from shared folder that I trust:

PowerShell -file "\\server\scripts\my.ps1"

But I get a security warning, and have to press 'R' to continue

> Security Warning Run only scripts that > you trust. While scripts from the > Internet can be useful, this script > can potentially harm your computer. Do > you want to run > \server\scripts\my.ps1? [D] Do not > run [R] Run once [S] Suspend [?] > Help (default is "D"): d

Can I ignore this warning? The desired pseudo code I want is:

PowerShell -IGNORE_SECURITY_WARNING -file "\\server\scripts\my.ps1"

Security Solutions


Solution 1 - Security

This is touched in "PowerShell Execution Policies in Standard Images" on Lee Holmes' Blog and "PowerShell’s Security Guiding Principles" on the Windows Power Shell Blog .

Summary Some machines treat UNC paths as the big bad internet, so PowerShell treats them as remote files. You can either disable this feature on those servers (UncAsIntranet = 0,) or add the remote machines to your trusted hosts.

If you want to do neither, PowerShell v2 supports an -ExecutionPolicy parameter that does exactly what your pseudocode wants. PowerShell -ExecutionPolicy Bypass -File (...).

Solution 2 - Security

To avoid warnings, you can:

Set-ExecutionPolicy bypass

Solution 3 - Security

If you're running into this error from a downloaded powershell script, you can unblock the script this way:

  1. Right-click on the .ps1 file in question, and select Properties

  2. Click Unblock in the file properties

    enter image description here

  3. Click OK

Solution 4 - Security

Just assign 1 to SEE_MASK_NOZONECHECKS env variable

$env:SEE_MASK_NOZONECHECKS = 1
Start-Process $msi_file_path /qn -Wait | out-null

Solution 5 - Security

Try this, edit the file with:

notepad foo.ps1:Zone.Identifier

And set 'ZoneId=0'

Solution 6 - Security

None of this worked in my specific instance. What did was changing to a NetBIOS name from the FQDN.

Instead of:
\\server.domain.net\file.ps1
use:
\\server\file.ps1

Using the name bypasses the "automatically detect intranet network" config in IE.

See Option 1 in the blog here: http://setspn.blogspot.com/2011/05/running-powershell-scripts-from-unc.html

Solution 7 - Security

I made this powershell script to unblock all files on a share on my server

Get-ChildItem "\\ServerName\e$\MyDirectory\" -Recurse -File | % {
       Unblock-File -Path $_.FullName
}

Solution 8 - Security

You want to set the execution policy on your machine using Set-ExecutionPolicy:

Set-ExecutionPolicy Unrestricted

You may want to investigate the various execution policies to see which one is right for you. Take a look at the "help about_signing" for more information.

Solution 9 - Security

Did you download the script from internet?

Then remove NTFS stream from the file using sysinternal's streams.exe on command line.

cmd> streams.exe .\my.ps1

Now try to run the script again.

Solution 10 - Security

Assume that you need to launch ps script from shared folder

copy \\\server\script.ps1 c:\tmp.ps1 /y && PowerShell.exe -ExecutionPolicy Bypass -File c:\tmp.ps1 && del /f c:\tmp.ps1

P.S. Reduce googling)

Solution 11 - Security

It is very simple to do, open your PowerShell and write the following command if you have number of ps1 files. here you have to change the path with your path.

PS C:\Users> Get-ChildItem -Path "D:\downlod" -Recurse | Unblock-File

Solution 12 - Security

Try set-executionpolicy "Policyname" -force switch and the warnings pop-up should not come.

Solution 13 - Security

For those who want to access a file from an already loaded PowerShell session, either use Unblock-File to mark the file as safe (though you already need to have set a relaxed execution policy like Unrestricted for this to work), or change the execution policy just for the current PowerShell session:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionalex2k8View Question on Stackoverflow
Solution 1 - SecurityLeeHolmesView Answer on Stackoverflow
Solution 2 - SecurityAlfredo JiménezView Answer on Stackoverflow
Solution 3 - SecuritymopsledView Answer on Stackoverflow
Solution 4 - SecurityJameel GrandView Answer on Stackoverflow
Solution 5 - SecurityDon WerveView Answer on Stackoverflow
Solution 6 - SecuritylightwingView Answer on Stackoverflow
Solution 7 - SecurityPeter VegView Answer on Stackoverflow
Solution 8 - SecurityzdanView Answer on Stackoverflow
Solution 9 - Securitydance2dieView Answer on Stackoverflow
Solution 10 - SecurityAlexView Answer on Stackoverflow
Solution 11 - SecuritySapnanduView Answer on Stackoverflow
Solution 12 - SecurityswapnilView Answer on Stackoverflow
Solution 13 - SecuritylauxjpnView Answer on Stackoverflow