当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

作者:精品下载站 日期:2024-12-14 09:49:23 浏览:14 分类:玩电脑

如何在服务器上使用 PowerShell 获取 Windows 功能


在本文中,我将演示如何在服务器上使用 PowerShell 获取 Windows 功能。 Get-WindowsFeature cmdlet 列出服务器上安装的所有 Windows 功能。

如果系统要求您查找特定服务器上安装的功能,您可以使用 PowerShell 来完成该任务。手动列出已安装的功能需要时间,并且当设置中有多个服务器时,您无法执行此操作。

有多种方法可以找到服务器上已安装的功能,包括配置管理器和第三方工具。但是,PowerShell 是发现 Windows 服务器上安装了哪些功能的最直接且免费的方法。

关于 Get-WindowsFeature Cmdlet

Get-WindowsFeature cmdlet 获取有关可供安装以及已安装在运行 Windows Server 的计算机或运行 Windows Server 的脱机虚拟硬盘 (VHD) 上的功能的信息。

显然,Windows 功能和角色仅在服务器操作系统上可用,而在客户端操作系统上不可用。因此,Get-WindowsFeature cmdlet 只能在服务器操作系统上执行。

您可以与 Get-WindowsFeature cmdlet 一起指定以下参数。

  • -姓名
  • -VHD
  • -计算机名
  • -凭据
  • -日志路径

如何使用 PowerShell 获取 Windows 功能

让我们看一下使用 Get-WindowsFeature cmdlet 通过 PowerShell 获取 Windows 角色和功能的一些示例。

列出服务器上的所有 Windows 功能

运行以下 PowerShell 命令以列出 Windows Server 上可用和安装的所有功能。

Get-WindowsFeature

在命令输出中,显示服务器上所有已安装和可用的安装功能的摘要。显示名称列显示 Windows 功能的名称,而“安装状态”列指示功能是否已安装或可用。

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

查找 Windows Server 上所有已安装的功能

如果您想了解给定 Windows Server 上安装的功能,请在 PowerShell 窗口中运行以下命令。

Get-WindowsFeature | where{$_.InstallState -eq "Installed"}

在下面的屏幕截图中,我们看到 PowerShell 命令输出显示了服务器上安装的所有 Windows 功能。

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

列出所有未安装的 Windows 功能

要列出服务器上未安装的 Windows 功能,您可以使用以下 PowerShell 命令。

Get-WindowsFeature | where{!($_.InstallState -eq "Installed")}

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

使用名称或通配符获取已安装的 Windows 功能

如果您需要查找服务器上安装的特定功能,只需输入名称或显示名称即可。如果您不知道功能/角色的全名,可以使用通配符来查找功能。

例如,在 Windows Server 上,如果您想查找以“Cert”开头的已安装功能,可以使用以下命令。

 Get-WindowsFeature *Cert*

以下命令输出显示名称以 Cert 开头的所有 Windows 功能。

[X] Active Directory Certificate Services               AD-Certificate                 Installed
    [X] Certification Authority                         ADCS-Cert-Authority            Installed
    [ ] Online Responder                                ADCS-Online-Cert               Available
            [ ] Centralized SSL Certificate Support     Web-CertProvider               Available
            [ ] IIS Client Certificate Mapping Authe... Web-Cert-Auth                  Available

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

查找远程 Windows Server 上已安装的功能

如果您想列出远程 Windows Server 上安装的 Windows 功能,可以使用 PowerShell。此方法很方便,因为您无需登录远程 Windows Server 即可获取这些功能。

在 PowerShell 窗口中运行以下命令以获取远程服务器上安装的 Windows 功能的列表。以下命令获取名称以remote开头的远程服务器上的所有已安装功能。

Get-WindowsFeature -ComputerName "ServerName" -Name *Remote*

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

您可以使用以下 PowerShell 命令查找多个远程 Windows 服务器上已安装功能的列表。在运行该命令之前,请将计算机名称替换为服务器名称。

Invoke-Command -ComputerName computername1,computername2 -ScriptBlock {Get-WindowsFeature *remote*}

[玩转系统] 如何在服务器上使用 PowerShell 获取 Windows 功能

阅读下一步

  • 如何使用 PowerShell 卸载 Windows 更新
  • 如何使用 PowerShell 更改 RDP 端口
  • 使用 PowerShell 列出所有 Azure 区域 | Azure 云外壳
  • 有用的 TPM PowerShell CmdLet 列表
  • 如何使用 PowerShell 获取公共 IP 地址

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯