如何更改我的默认PowerShellconfiguration文件/数字签名我的$configuration文件?

我试图创build一个我的PowerShell环境的终极设置。

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

当我启动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.

最简单的解决scheme是

 Set-ExecutionPolicy RemoteSigned 

但是这将运行在本地磁盘上的所有脚本(并且不在远程区域 – 就像通过IE下载)

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

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

签署Powershell脚本时,也可以阅读Scott Hanselman的智慧话语。

在这里你有3个选项,你可以让你的脚本由一个值得信赖的提供者签名,或者至less是一个你信任的提供者,或者你可以使用Set-ExecutionPolicy来设置powershell来允许外部脚本:

  Set-ExecutionPolicy RemoteSigned 

将在本地机器上运行任何不是来自互联网的脚本

 Set-ExecutionPolicy Unrestricted 

将允许任何脚本运行,但如果您从互联网上下载它会要求您确认您想要运行它。

最后,您可以通过右键单击该文件来设置要运行的特定脚本,然后单击“属性”。 在对话框的底部点击“取消阻止”。