[玩转系统] PowerShell 获取 WindowsOptionalFeature
作者:精品下载站 日期:2024-12-14 17:26:17 浏览:13 分类:玩电脑
PowerShell 获取 WindowsOptionalFeature
使用 PowerShell 中的 Get-WindowsOptionalFeature
cmdlet 获取有关所有功能的信息,包括 Windows 映像中的可选功能。
Get-WindowsOptionalFeature
用于获取正在运行的操作系统中的 Windows 可选功能列表、检索包中的可选功能列表以及获取有关已安装映像中的功能的详细信息。
Get-WindowsOptionalFeature
语法包含可用于指定功能名称、包名称、在线、包路径、路径、Windows 目录和日志级别的参数。
在本文中,我们将讨论如何在 PowerShell 中使用 Get-WindowsOptionalFeature cmdlet 来获取有关所有功能的信息。
酷提示:Get-WindowsOptionalFeature 需要提升。您必须以“以管理员身份运行”身份打开 PowerShell 终端才能运行 cmdlet。
Get-WindowsOptionalFeature 的语法是什么
Get-WindowsOptionalFeature 的语法如下所示。
Get-WindowsOptionalFeature
[-FeatureName <String>]
[-PackageName <String>]
[-PackagePath <String>]
[-Online]
-Path <String>
[-WindowsDirectory <String>]
[-SystemDrive <String>]
[-LogPath <String>]
[-ScratchDirectory <String>]
[-LogLevel <LogLevel>]
[<CommonParameters>]
下面给出了 Get-WindowsOptionalFeature 中使用的参数。
-FeatureName:获取详细信息的功能名称。功能名称区分大小写。
-PackageName: Windows 映像中列出的包的名称。使用 -PackageName 参数获取包中的所有功能。您可以使用 FeatureName 和 PackageName 参数来获取有关包中特定功能的更多详细信息。
-PackagePath: 它指定Windows 映像中.cab 文件的名称。使用此参数可以获取包中的所有功能。
-路径: 它指定您将提供服务的脱机 Windows 映像的根目录的完整路径。
-Online: 使用 Online 参数指定本地计算机上正在运行的操作系统。
-LogPath:它指定要登录的完整路径和文件名。如果未设置,则它使用默认路径 %WINDIR%\Logs\Dism\dism.log
。
-ScratchDirectory:它指定在服务期间提取文件以供使用时使用的临时目录。该目录必须存在于本地。如果未指定,它将使用%Windows\%Temp%
。
让我们通过示例了解 DISM 模块中的 PowerShell Get-WindowsOptionalFeature cmdlet。在下面的示例中,我们将使用该命令获取包中的功能列表,并获取有关已安装映像中的功能的详细信息。
如何列出正在运行的操作系统中的可选功能
使用 PowerShell 中的 Get-WindowsOptionalFeature cmdlet 获取操作系统中可选功能的列表。
Get-WindowsOptionalFeature -Online
在上面的 PowerShell 脚本中,命令 Get-WindowsOptionalFeature
使用参数 -Online
列出正在运行的 Windows 操作系统中的所有可选功能。
上述命令的输出检索所有功能的列表,并显示正在运行的操作系统中所有功能的功能名称和状态(启用或禁用)。
仅列出正在运行的操作系统中启用的可选功能
Windows 操作系统包含启用或禁用的可选功能。您可以使用过滤器来获取正在运行的操作系统中已启用的可选功能的列表,以检查状态是否已启用。
Get-WindowsOptionalFeature -Online | Where {$_.state -eq 'Enabled'} | Select FeatureName
在上面的 PowerShell 脚本中,Get-WindowsOptionalFeature
cmdlet 使用 -Online
参数列出所有可用功能,并使用管道运算符将其发送到下一个命令。
Where
条件检查功能的状态是否等于“已启用”并选择“FeatureName”。
上述命令的输出显示已启用的可选功能的列表。
仅列出正在运行的操作系统中禁用的可选功能
您可以使用 Get-WindowsOptionalFeatures 和 where 条件检索正在运行的操作系统中禁用的可选功能,以检查功能状态是否已禁用。
Get-WindowsOptionalFeature -Online | Where {$_.state -eq 'Disabled'} | Select FeatureName
在上面的 PowerShell 脚本中,Get-WindowsOptionalFeature
命令使用参数 -Online
获取所有可选功能的列表,并使用 Where
条件检查状态是否禁用,并显示功能名称。
它显示正在运行的操作系统中禁用的可选功能。
获取有关已安装图像中的功能的详细信息
使用带有参数 -Path 和 -FeatureName 的 Get-WindowsOptionalFeature cmdlet 来获取有关已装载映像中的功能的详细信息。
Get-WindowsOptionalFeature -Path "D:\Win11" -FeatureName Hearts
在上面的 PowerShell 脚本中,cmdlet Get-WindowsOptionalFeature
使用 -Path
参数指定脱机 Windows 映像的根目录的路径。它获取有关已安装映像中名为 Hearts
的功能的详细信息。
获取有关已安装映像中指定包中的功能的详细信息
Get-WindowsOptionalFeature -Path "D:\Win11" -FeatureName "Hearts" -PackagePath "C:\packages\package.cab"
在上面的 PowerShell 脚本中,Get-WindowsOptionalFeature
使用 Path
参数指定挂载到 D:\Win11 的 Windows 映像的路径,它显示有关 c:\packages\package.cab 包中的 Hearts 功能的详细信息。
酷提示:如何使用 PowerShell 和 Cmd 安装 telnet 客户端!
使用通配符获取有关功能的详细信息
您可以使用通配符在命令中指定功能名称以获取有关它的详细信息。
Get-WindowsOptionalFeature -Online -FeatureName *Hyper-V*
在上述 PowerShell 脚本中,Get-WindowsOptionalFeature
使用 -Online
参数列出所有可选功能并检查功能名称*Hyper-V*
在其中。
它返回有关正在运行的操作系统中的 Hyper-V 可选功能的详细信息。
用于获取有关 Hyper-v 功能名称详细信息的上述脚本的输出为:
PS C:\> Get-WindowsOptionalFeature -Online -FeatureName *Hyper-V*
FeatureName : Microsoft-Hyper-V-All
DisplayName : Hyper-V
Description : Provides services and management tools for creating and running virtual machines and their
resources.
RestartRequired : Possible
State : Disabled
CustomProperties :
FeatureName : Microsoft-Hyper-V
DisplayName : Hyper-V Platform
Description : Provides the services that you can use to create and manage virtual machines and their resources.
RestartRequired : Possible
State : Disabled
CustomProperties :
您可以使用 Get-WindowsOptionalFeature cmdlet 通过 PowerShell 检查正在运行的操作系统中是否启用了 hyper-v。
获取远程计算机的 Windows 可选功能
您可以使用 Invoke-Command
cmdlet 获取有关远程计算机上可选功能的信息。
以下 PowerShell 脚本将获取有关名为“incorp-eu-101”的远程计算机上的可选功能的信息
# Specify the remote computer name
$remoteComputerName = "incorp-eu-101"
# Get the list of optional features on remote computer
$features = Invoke-Command -ComputerName $remoteComputerName {Get-WindowsOptionalFeature -Online}
# Print the list of optional features
$features
上述 PowerShell 脚本使用 Invoke-Command
cmdlet 在远程计算机上运行 Get-WindowsOptionalFeature
cmdlet,检索所有可选功能的列表并将其存储在变量 中$功能
。最后,它将可选功能列表打印到控制台。
在 Windows 操作系统上获取 Windows 可选功能 RSAT 状态
RSAT(远程服务器管理工具)可以安装在 Windows 10/Windows 11 或 Windows Server 系统上。要在安装之前检查 Windows 操作系统上的 RSAT 状态,请运行以下 PowerShell 脚本。
Get-WindowsOptionalFeature -Online -FeatureName *RSAT* | Select-Object FeatureName, state
在上面的 PowerShell 脚本中,Get-WindowsOptionalFeature cmdlet 获取正在运行的操作系统(此处为 Windows 10)上有关 RSAT 的详细信息,并显示其功能名称和状态。
获取 Windows 操作系统上的 Windows 可选功能 Internet Explorer 状态
您可以使用 PowerShell 中的 Get-WindowsOptionalFeature cmdlet 来获取功能名称“Internet Explorer”详细信息及其在 Windows 操作系统上的状态。
Get-WindowsOptionalFeature -Online -FeatureName *Internet-Explorer* | Select-Object FeatureName,State
在上面的 PowerShell 脚本中,Get-WindowsOptionalFeature 命令检索“Internet-Explorer”功能的详细信息,并在给定的 Windows 10 操作系统上将其状态显示为“已启用”。
上述 PowerShell 脚本的输出是:
PS C:\> Get-WindowsOptionalFeature -Online -FeatureName *Internet-Explorer* | Select-Object FeatureName,State
FeatureName State
----------- -----
Internet-Explorer-Optional-amd64 Enabled
如何在Windows操作系统上检查SMB1协议状态?
使用 Get-WindowsOptionalFeature cmdlet 获取有关 SMB1Protocol 功能的详细信息。它将获取 SMB1Protocol
功能名称、显示名称、描述和状态。
Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
在上述 PowerShell 脚本中,Get-WindowsOptionalFeature
cmdlet 使用 FeatureName
参数指定 SMB1Protocol 名称并检索其属性。
上述脚本的输出在 Windows 10 系统(正在运行的操作系统)上将 SMB1Protocol 状态显示为“已禁用”。
PS C:\> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
FeatureName : SMB1Protocol
DisplayName : SMB 1.0/CIFS File Sharing Support
Description : Support for the SMB 1.0/CIFS file sharing protocol, and the Computer Browser protocol.
RestartRequired : Possible
State : Disabled
CustomProperties :
ServerComponent\Description : Support for the SMB 1.0/CIFS file sharing protocol, and the Computer Browser protocol.
ServerComponent\DisplayName : SMB 1.0/CIFS File Sharing Support
ServerComponent\Id : 487
ServerComponent\Type : Feature
ServerComponent\UniqueName : FS-SMB1
ServerComponent\Deploys\Update\Name : SMB1Protocol
结论
我希望上述有关 PowerShell Get-WindowsOptionalFeature 主题的文章列出所有可选功能对您有所帮助。
我们学习了如何在 PowerShell 中使用 cmdlet Get-WindowsOptionalFeature 列出所有可选功能、获取有关正在运行的操作系统中的功能的详细信息以及使用不同参数安装的映像。
您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag