Script for automating the management of Windows Server roles and features.

PHOTO EMBED

Fri Jan 27 2023 06:37:08 GMT+0000 (Coordinated Universal Time)

Saved by @thefunkytechguy #powershell #activedirectory

$role = "DHCP"
$feature = "RSAT-DHCP"
$computers = "Server1", "Server2", "Server3"
$action = Read-Host "Enter 'install', 'uninstall', or 'check' for the role/feature"

foreach ($computer in $computers) {
    Invoke-Command -ComputerName $computer -ScriptBlock {
        if ($action -eq "install") {
            Install-WindowsFeature -Name $role, $feature -IncludeAllSubFeature -IncludeManagementTools
        } elseif ($action -eq "uninstall") {
            Uninstall-WindowsFeature -Name $role, $feature -Remove
        } elseif ($action -eq "check") {
            Get-WindowsFeature -Name $role, $feature | Format-Table -Property Name, DisplayName, Installed
        } else {
            Write-Host "Invalid action specified"
        }
    }
}
content_copyCOPY

https://www.thefunkytechguy.co.za