如何使用 PowerShell 移除 Windows 功能?
要移除 Windows 功能,可以使用 Remove-WindowsFeature 命令,该命令与功能名称一起使用。
Remove-WindowsFeature Search-Service -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service}
VERBOSE: Uninstallation succeeded.如果 Windows 功能具有管理工具,如Web 服务器 (IIS)功能,可以在命令行中添加相同的工具。如果服务器需要重新启动,则可以添加-Restart参数。例如:
Remove-WindowsFeature Web-Server -IncludeManagementTools -Restart -Verbose
如果检查-Name参数,则它支持字符串数组。这意味着我们可以一起移除多个角色和功能。
help Remove-WindowsFeature -Parameter Name -Name <Feature[]>
将多个功能一起移除并使用**-LogPath**参数以在本地计算机上记录输出的示例。
PS C:\Users\Administrator> Remove-WindowsFeature Windows-Server-Backup, Search-Service -LogPath C:\Temp\Uninstallfeatures.txt -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service, Windows Server Ba...
VERBOSE: Uninstallation succeeded.要在远程计算机上移除 Windows 功能,需要使用-ComputerName参数。例如:
Remove-WindowsFeature Windows-Server-Backup, Search-Service -ComputerName Test1-Win2k16 -Verbose
输出
PS C:\Scripts\IISRestart> Remove-WindowsFeature Windows-Server-Backup, Search-Service -ComputerName Test1-Win2k16 -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service, Windows Server Ba...
VERBOSE: Uninstallation succeeded.此-ComputerName参数是字符串参数,而不是数组,如下所示,其使用说明命令。
help Remove-WindowsFeature -Parameter ComputerName -ComputerName [<String≫]
因此,要从多台计算机上移除 Windows 功能,我们需要使用foreach循环和-ComputerName参数,或者通过 Invoke-Command。使用**Invoke-Command**会更轻松。
Invoke-Command -ComputerName Test1-Win2k16,Test1-Win2k12 -ScriptBlock{Remove-WindowsFeature Windows-Server-Backup,Search-Service}上述命令将确保移除多台远程计算机上的多个功能。
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP