如何更改我的默认 PowerShell 配置文件/对我的 $profile 文件进行数字签名?

Bre*_*tra 14 windows powershell

我尝试为我的 powershell 环境创建一个终极设置。

我用一堆语句创建了“Microsoft.PowerShell_profiles.ps1”来设置我的默认配置文件。

但是,当我开始 PowerShell 会话时,我得到:

File C:\Documents and Settings\xxx\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded. The file C:\Documents and Settings\xxx\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 is not digitally signed. The script will not execute on the system.

squ*_*man 18

默认情况下,Powershell 会限制您运行“不安全”脚本。运行该get-executionpolicy命令以查看您的系统级别。要降低限制,您可以运行Set-ExecutionPolicy并为其提供以下其中一项作为参数:

  • 受限– 不能运行任何脚本。Windows PowerShell 只能在交互模式下使用。
  • AllSigned – 只能运行由受信任发布者签名的脚本。
  • RemoteSigned – 下载的脚本必须由受信任的发布者签名才能运行。
  • 无限制– 无限制;可以运行所有 Windows PowerShell 脚本。

还可以阅读 Scott Hanselman 关于签署 Powershell 脚本的智慧之言。

  • +1 比接受的答案好得多 (2认同)

mih*_*ihi 8

最简单的解决方案是

Set-ExecutionPolicy RemoteSigned
Run Code Online (Sandbox Code Playgroud)

但这将运行本地磁盘上的所有脚本(并且不在远程区域中 - 例如通过 IE 下载)

  • 我就是这样做的,但后来我觉得很脏。 (6认同)