Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore 'Security Warning' running script from command line

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" 
like image 487
alex2k8 Avatar asked Apr 08 '09 00:04

alex2k8


People also ask

How do I run a PowerShell script without 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.

How do you set up an execution policy?

Set-ExecutionPolicy uses the ExecutionPolicy parameter to specify the AllSigned policy. The Scope parameter specifies the CurrentUser. To view the execution policy settings, use the Get-ExecutionPolicy cmdlet with the List parameter. The effective execution policy for the user becomes AllSigned.


2 Answers

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 (...).

like image 120
LeeHolmes Avatar answered Oct 13 '22 05:10

LeeHolmes


To avoid warnings, you can:

Set-ExecutionPolicy bypass 
like image 25
Alfredo Jiménez Avatar answered Oct 13 '22 06:10

Alfredo Jiménez