Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Uninstall-WindowsFeature is a PowerShell cmdlet used in Windows Server environments to remove roles, role services, and features that are installed on the server. This cmdlet is particularly useful for administrators who need to manage server roles and features efficiently through automation scripts or command-line operations.
Examples:
Basic Uninstallation of a Windows Feature:
Suppose you want to remove the "Web-Server" feature (IIS) from your Windows Server. You can do this using the Uninstall-WindowsFeature cmdlet in PowerShell.
Uninstall-WindowsFeature -Name Web-Server
This command will uninstall the Web Server (IIS) role from the server.
Uninstalling Multiple Features:
If you need to uninstall multiple features at once, you can specify them in a comma-separated list.
Uninstall-WindowsFeature -Name Web-Server, Web-Mgmt-Tools
This command will remove both the Web Server and Web Management Tools features.
Uninstalling a Feature and Removing Management Tools:
By default, the Uninstall-WindowsFeature cmdlet does not remove the management tools associated with a feature. If you want to remove these tools as well, use the -Remove
parameter.
Uninstall-WindowsFeature -Name Web-Server -Remove
This command will uninstall the Web Server role and remove the associated management tools.
Checking the Result of an Uninstallation:
After running the Uninstall-WindowsFeature cmdlet, you might want to verify that the feature was successfully removed. You can do this by checking the Success
property of the result.
$result = Uninstall-WindowsFeature -Name Web-Server
if ($result.Success) {
Write-Host "The feature was successfully uninstalled."
} else {
Write-Host "The feature could not be uninstalled."
}
Using Uninstall-WindowsFeature in a Script:
You can incorporate the Uninstall-WindowsFeature cmdlet into a PowerShell script to automate the removal of features across multiple servers.
$servers = @("Server1", "Server2", "Server3")
foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock {
Uninstall-WindowsFeature -Name Web-Server -Remove
}
}
This script will connect to each server in the list and uninstall the Web Server role along with its management tools.