views:

2119

answers:

4

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

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

But get security warning, and have to press 'R'

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? Desired pseudo code is:

powershell -IGNORE_SECURITY_WARNING -file "\\server\scripts\my.ps1"
+1  A: 

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.

zdan
A: 

Try this, edit the file with:

notepad foo.ps1:Zone.Identifier

And set 'ZoneId=0'

Don Werve
+1  A: 

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.

Sung Meister
+7  A: 

This is touched on here: http://www.leeholmes.com/blog/PowerShellExecutionPoliciesInStandardImages.aspx and here: http://blogs.msdn.com/powershell/archive/2008/09/30/powershell-s-security-guiding-principles.aspx.

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

Lee Holmes [MSFT]

LeeHolmes
Thank you! -ExecutionPolicy Bypass is exactly what I was looking for.
alex2k8