如何使用 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}

上述命令將確保移除多臺遠端計算機上的多個功能。

更新於:2020 年 8 月 26 日

3000 多次觀看

開啟您的職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.