可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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"
回答1:
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 (...)
.
回答2:
To avoid warnings, you can:
Set-ExecutionPolicy bypass
回答3:
If you're running into this error from a downloaded powershell script, you can unblock the script this way:
Right-click on the .ps1
file in question, and select Properties
Click Unblock in the file properties

Click OK
回答4:
Just assign 1 to SEE_MASK_NOZONECHECKS env variable
$env:SEE_MASK_NOZONECHECKS = 1 Start-Process $msi_file_path /qn -Wait | out-null
回答5:
Try this, edit the file with:
notepad foo.ps1:Zone.Identifier
And set 'ZoneId=0'
回答6:
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.
回答7:
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.
回答8:
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
回答9:
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)
回答10:
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 }