BAC*_*CON 55 powershell code-signing powershell-2.0
我在64位Windows 7 Professional上使用Windows PowerShell 2.0 .我的桌面上有一个脚本,当我尝试运行它时会导致以下错误:
File C:\Users\UserName\Desktop\Script.ps1 cannot be loaded. The file C:\Users\UserName\Desktop\Script.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:54
+ C:\Users\UserName\Desktop\TestGetWindowsUpdateLog.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Run Code Online (Sandbox Code Playgroud)
我既是域管理员又是本地管理员,如果我运行Get-ExecutionPolicy -List,我可以看到Group Policy Object我创建的配置PowerShell是RemoteSigned在机器级正确应用执行策略:
Scope ExecutionPolicy
----- ---------------
MachinePolicy RemoteSigned
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
Run Code Online (Sandbox Code Playgroud)
我自己在记事本中创建了脚本,并使用Sysinternals的流实用程序和文件Properties对话框来确认脚本没有被视为来自Internet.如果我将脚本复制到域服务器上的网络共享,则允许执行.如果我运行,Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine那么仍然不允许执行本地脚本,这是有道理的,因为MachinePolicy作用域中的执行策略将优先.
据记载about_Execution_Policies,该RemoteSigned政策意味着:
脚本可以运行.
需要来自受信任发布者的数字签名,用于从Internet下载的脚本和配置文件(包括电子邮件和即时消息程序).
在运行的脚本上以及在本地计算机上编写的脚本(不是从Internet下载)上不需要数字签名.
风险从Internet以外的来源运行未签名的脚本并签名但是恶意的脚本.
我的脚本没有签名,但由于它是在本地创建和执行的,因此它应满足上面的第三个要点.那么为什么它不被允许运行?为什么当该要求仅适用于来自Internet的文件时,PowerShell会抱怨我的脚本"未经过数字签名"?为什么它不再关心脚本在从网络共享运行时没有被签名?
小智 93
文件被阻止了吗?我有同样的问题,可以通过右键单击.PS1文件,属性并选择取消阻止来解决它.
And*_*ndi 64
有些事要检查:
你可以改为不受限制吗?
Set-ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)
是否制定了组策略?
Computer Configuration\Administrative Templates\Windows Components\Windows PowerShellUser Configuration\Administrative Templates\Windows Components\Windows PowerShell另外,你是如何调用Script.ps1的?
这是否允许它运行?
powershell.exe -executionpolicy bypass -file .\Script.ps1
Run Code Online (Sandbox Code Playgroud)
小智 16
我发现在将映射驱动器的 PS1 文件运行到 Dropbox 时,我总是收到此错误。打开 PS1 的属性时,没有“解锁”。
唯一对我有用的是
powershell.exe -executionpolicy bypass -file .\Script.ps1
当您运行 .ps1 PowerShell 脚本时,您可能会收到消息“.ps1 未经过数字签名。该脚本不会在系统上执行。” 要修复它,您必须运行以下命令来运行 Set-ExecutionPolicy 并更改执行策略设置。
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Run Code Online (Sandbox Code Playgroud)
我最终将其跟踪到.NET代码访问安全性.我有一些内部开发的二进制模块,存储在网络共享上并从网络共享中执行.为了让.NET 2.0/PowerShell 2.0加载它们,我在Intranet代码组中添加了一个URL规则来信任该目录:
PS C:\Users\UserName> & "$Env:SystemRoot\Microsoft.NET\Framework64\v2.0.50727\caspol.exe" -machine -listgroups
Microsoft (R) .NET Framework CasPol 2.0.50727.5420
Copyright (c) Microsoft Corporation. All rights reserved.
Security is ON
Execution checking is ON
Policy change prompt is ON
Level = Machine
Code Groups:
1. All code: Nothing
1.1. Zone - MyComputer: FullTrust
1.1.1. StrongName - ...: FullTrust
1.1.2. StrongName - ...: FullTrust
1.2. Zone - Intranet: LocalIntranet
1.2.1. All code: Same site Web
1.2.2. All code: Same directory FileIO - 'Read, PathDiscovery'
1.2.3. Url - file://Server/Share/Directory/WindowsPowerShell/Modules/*: FullTrust
1.3. Zone - Internet: Internet
1.3.1. All code: Same site Web
1.4. Zone - Untrusted: Nothing
1.5. Zone - Trusted: Internet
1.5.1. All code: Same site Web
Run Code Online (Sandbox Code Playgroud)
请注意,根据安装的.NET版本以及是否为32位或64位Windows,caspol.exe可以存在于以下位置,每个位置都有自己的安全配置(security.config):
$Env:SystemRoot\Microsoft.NET\Framework\v2.0.50727\$Env:SystemRoot\Microsoft.NET\Framework64\v2.0.50727\$Env:SystemRoot\Microsoft.NET\Framework\v4.0.30319\$Env:SystemRoot\Microsoft.NET\Framework64\v4.0.30319\删除组1.2.3(让我使用CAS的默认配置)后,本地脚本现在可以再次运行.它已经有一段时间,因为我已经与中科院修修补补,我不知道为什么我的规则似乎与授予干扰FullTrust到MyComputer,但由于CAS是不赞成的.NET 4.0(在其上的PowerShell 3.0的基础),我我猜这是一个有争议的问题.
小智 7
如果从网络位置(即另一台计算机)复制文件,则Windows可能已阻止该文件。右键单击该文件,然后单击“取消阻止”按钮,看看它是否有效。
| 归档时间: |
|
| 查看次数: |
144015 次 |
| 最近记录: |