安装 IIS 7.0 PowerShell 管理单元

作者:Thomas Deml

介绍

在以下演练中,你将了解如何安装 IIS PowerShell 管理单元以及如何启动 IIS PowerShell 管理控制台。

先决条件

IIS PowerShell 管理单元需要满足以下先决条件:

  • Windows Server 2008、Windows Server 2008 R2、Windows Vista Service Pack 1 或 Windows 7
  • Microsoft PowerShell 1.0 或 2.0

若要安装 IIS PowerShell 管理单元,请执行以下操作:

  1. 下载 IIS PowerShell 管理单元 x86 或 x64 版本。
  2. 运行 MSI 文件来安装 IIS PowerShell 管理单元。

使用 IIS PowerShell 管理单元

必须将 PowerShell 管理单元(例如 IIS PowerShell 管理单元)注册到 PowerShell。 有两种方法可以实现此目的:

使用 IIS PowerShell 管理控制台自动注册

IIS PowerShell 管理单元设置将创建新的程序菜单快捷方式。 通过启动此快捷方式,会自动注册 IIS PowerShell 管理单元。 单击“开始”菜单,然后选择“所有程序”-“IIS 7.0 扩展”-“IIS PowerShell 管理控制台”。 新的 PowerShell 命令窗口的提示设置为“IIS:”- 它是IIS 管理单元命名空间的根目录。

手动注册

如果要在现有的 PowerShell 命令窗口中使用 IIS PowerShell 管理单元,必须手动注册 IIS 管理单元。 要实现此目的,只需执行位于“$env:programfiles\IIS\PowerShellProvider”目录的 IISConsole.PSC1 文件:

PS C:\> & "$env:programfiles\IIS\PowerShellSnapin\iisConsole.psc1"

关于安全性

用户访问控制

需要管理员权限才能管理 IIS 配置。 这意味着必须运行提升的 PowerShell 命令窗口。 确保始终通过“以管理员身份运行”菜单项启动 PowerShell。

PowerShell 执行策略

你可能会看到以下错误,具体取决于 PowerShell 执行权限。

Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
Do you want to run software from this untrusted publisher?
File C:\Program Files\IIS\PowerShellProvider\iisprovider.types.ps1xml is published by CN=Microsoft
Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your
system. Only run scripts from trusted publishers.
[V] Never run  [D] Do not run  [R] Run once  [A] Always run  [?] Help (default is "D"):

尽管 IIS PowerShell 提供程序文件都有签名,但只有在 PowerShell 的执行策略设置为“受限”时,它才会信任由“可信发布者”签名的脚本。 有两种方法来解决此问题。

放宽执行策略

如果看到上述错误,那么执行策略可能设置为“受限”。 若要信任其他代码,可以将执行策略设置为“RemoteSigned”,这样本地脚本无需数字签名即可运行。 在提升的 PowerShell 窗口中执行以下命令:

PS C:\> Set-ExecutionPolicy RemoteSigned

若要详细了解签名和执行策略,请执行以下命令。

help about_signing

将 Microsoft 代码签名证书添加到可信发布者列表

若要信任 IIS 提供程序脚本和二进制文件,可以在上述对话框中点击“A”,它会将 IIS 管理单元使用的代码签名证书添加到可信发布者列表。 可执行以下命令来获取“可信发布者”列表:

dir cert:\CurrentUser\TrustedPublisher | fl

总结

在本演练中,你学习了如何自动或手动安装 IIS PowerShell 管理单元。