Install And Config PowerShell

必须先在计算机上安装和配置 Windows PowerShell 和 Windows 远程管理 (WinRM) 的正确版本,然后才能使用 Windows PowerShell。您必须使用 Windows Management Framework,其中包含 Windows PowerShell v2 和 WinRM 2.0 的正确版本。

如果您的计算机运行的是 Windows 7 或 Windows Server 2008 R2,则不必安装任何版本。Windows Management Framework 已经安装。

如果您的计算机运行的是下列操作系统之一,则可以下载并安装 Windows Management Framework:

  • Windows Vista Service Pack 1 (SP1) 或 Windows Vista Service Pack 2 (SP2)
  • Windows Server 2008 SP1 或 Windows Server 2008 SP2
  • Windows Server 2003 SP2
  • Windows XP SP3

快速入门:

  1. 从计算机上卸载以前版本的 Windows PowerShell
  2. 从计算机上卸载以前版本的 WinRM
  3. 安装 Windows Management Framework
  4. 验证 Windows PowerShell 是否可以运行脚本
  5. 验证 WinRM 是否允许 Windows PowerShell 建立连接

1.从计算机上卸载以前版本的 Windows PowerShell

必须先卸载 Windows PowerShell 的任何现有版本,然后才能安装 Windows Management Framework。

注意   对于 Windows 7 或 Windows Server 2008 R2,不必执行此步骤。

从 Windows Vista 上卸载 Windows PowerShell

  1. 在“控制面板”的“程序”中,打开“程序和功能”,然后卸载在已安装的程序列表中出现的任何 Windows PowerShell 实例。例如,Windows PowerShell v2 的 Community Technology Preview (CTP) 版本可能显示为 Windows PowerShell (TM) V2。
  2. 在“任务”下,选择“查看已安装的更新”并卸载在已安装的更新列表中出现的任何 Windows PowerShell 实例。例如,Windows PowerShell V1 可能作为以下某个 Microsoft 知识库文章编号所标识的一个 Windows 更新出现:
    • KB928439
    • KB923569

从 Windows Server 2008 上卸载 Windows PowerShell

  1. 启动“服务器管理器”,并转到“功能”。
    1. 单击“卸载功能”。
    2. 选择“Windows PowerShell”,并按照指示执行卸载。
  2. 在“控制面板”的“程序”中,打开“程序和功能”,然后卸载在已安装的程序列表中出现的任何 Windows PowerShell 实例。
  3. 在“任务”下,选择“查看已安装的更新”。卸载在已安装的更新列表中出现的任何 Windows PowerShell 实例。

从 Windows Server 2003 和 Windows XP 上卸载 Windows PowerShell

  1. 在“控制面板”中,打开“添加或删除程序”,然后卸载在已安装的程序列表中出现的任何 Windows PowerShell 实例。
  2. 在“添加或删除程序”中,选择“显示更新”。卸载在已安装的更新列表中出现的任何 Windows PowerShell 实例。例如,Windows PowerShell V1 可能作为知识库文章编号 KB926139 所标识的 Windows 更新出现。

2.从计算机上卸载以前版本的 WinRM

必须先卸载 WinRM 的任何现有版本,然后才能安装 Windows Management Framework。

注意   对于 Windows 7 或 Windows Server 2008 R2,不必执行此步骤。

从 Windows Vista 或 Windows Server 2008 上卸载 WinRM

  1. 在“控制面板”的“程序”中,打开“程序和功能”,然后卸载在已安装的程序列表中出现的 Windows 远程管理的任何实例。
  2. 在“任务”下,选择“查看已安装的更新”。卸载在已安装的更新列表中出现的 Windows 远程管理的任何实例。例如,WinRM 2.0 的 Community Technology Preview (CTP) 可能作为以下某个知识库文章编号所标识的 WindowsRemoteManagement 出现:
    • KB936059
    • KB950099

从 Windows Server 2003 和 Windows XP 上卸载 Windows PowerShell

  1. 在“控制面板”中,打开“添加或删除程序”,然后卸载在已安装的程序列表中出现的 Windows 远程管理的任何实例。
  2. 在“添加或删除程序”中,选择“显示更新”。卸载在已安装的更新列表中出现的 Windows 远程管理的任何实例。例如,WinRM 可能作为知识库文章编号 KB936059 所标识的 Windows 更新出现。

3.安装 Windows Management Framework

  • 下载并安装 Windows Management Framework。选择包含 Windows PowerShell v2 和 WinRM 2.0 且应用于您的操作系统、系统体系结构和语言的程序包。
    安装 WinRM 和 Windows PowerShell 之后,按照后续步骤中的介绍配置该软件,使其能够正常工作。
    注意   如果您的本地计算机受 Microsoft Internet Security and Acceleration (ISA) 服务器保护,则您可能必须在该计算机上安装 Windows 防火墙客户端或配置一个代理服务器,才能将 Windows PowerShell 连接到基于云的服务。有关详细信息,请参阅 Windows PowerShell:管理员常见问题

4.验证 Windows PowerShell 是否可以运行脚本

  1. 单击“开始”>“所有程序”>“附件”>“Windows PowerShell”。
  2. 执行以下操作之一以打开 Windows PowerShell:
    • 如果运行的是 Windows Vista、Windows 7 或 Windows Server 2008 R2,请右键单击“Windows PowerShell”并选择“以管理员身份运行”。当出现询问您是否要继续的用户帐户控制提示时,请选择“继续”。
    • 如果运行的是 Windows XP 或 Windows Server 2003,请单击“Windows PowerShell”。
  3. 运行以下命令:
    Get-ExecutionPolicy
    
  4. 如果返回的值是除 RemoteSigned 以外的任何其他值,则必须将该值更改为 RemoteSigned
    注意   若将脚本执行策略设置为 RemoteSigned,则只能运行在您的计算机上创建的脚本或由受信任的源签名的脚本。

使脚本能够在 Windows PowerShell 中运行

在您刚刚以管理员身份打开的 Windows PowerShell 会话中,运行以下命令:

Set-ExecutionPolicy RemoteSigned

5.验证 WinRM 是否允许 Windows PowerShell 建立连接

  1. 单击“开始”>“所有程序”>“附件”。
  2. 执行以下操作之一以打开命令提示符:
    • 如果运行的是 Windows Vista、Windows 7 或 Windows Server 2008 R2,请右键单击“命令提示符”并选择“以管理员身份运行”。当出现询问您是否要继续的用户帐户控制提示时,请选择“继续”。
    • 如果运行的是 Windows XP 或 Windows Server 2003,请单击“命令提示符”。
  3. 在命令提示符下,运行以下命令:
    net start winrm
    winrm get winrm/config/client/auth
    
    注意   如果 WinRM 服务已在运行,则不必启动它。可以通过运行 sc query winrm 命令检查 WinRM 服务的状态。
  4. 在结果中查找值 Basic = 。如果此值为 Basic = false,则必须将此值更改为 Basic = true
    注意   如果您已启动 WinRM 服务并且无需更改 Basic 值,请运行 net stop winrm 命令来停止 WinRM 服务。

将 WinRM 配置为支持基本身份验证

  1. 在您刚刚以管理员身份打开的命令提示符下,运行以下命令。大括号 { } 之间的值区分大小写:
    winrm set winrm/config/client/auth @{Basic="true"}
    
  2. 在命令输出中,验证值 Basic = true
    注意   如果您已启动 WinRM 服务,请运行 net stop winrm 命令来停止 WinRM 服务。

作者:Angelo Lee
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文地址:https://www.cnblogs.com/yefengmeander/p/2887639.html