PowerShell: Win2012R2 Win2016 检查并安装Windows Feature

$feature_list=
#iis components
"Web-Server",
"Web-WebServer",
"Web-Common-Http",
"Web-Default-Doc",
"Web-Dir-Browsing",
"Web-Http-Errors",
"Web-Static-Content",
"Web-Http-Redirect",
"Web-Health",
"Web-Http-Logging",
"Web-Custom-Logging",
"Web-Log-Libraries",
"Web-Request-Monitor",
"Web-Http-Tracing",
"Web-Performance",
"Web-Stat-Compression",
"Web-Security",
"Web-Filtering",
"Web-Basic-Auth",
"Web-Client-Auth",
"Web-Digest-Auth",
"Web-Url-Auth",
"Web-Windows-Auth",
"Web-App-Dev",
"Web-Net-Ext45",
"Web-Asp-Net45",
"Web-ISAPI-Ext",
"Web-ISAPI-Filter",
"Web-Includes",
"Web-Mgmt-Tools",
"Web-Mgmt-Console",
"Web-Mgmt-Compat",
"Web-Metabase",
"Web-WMI",
"Web-Lgcy-Mgmt-Console",
"Web-Lgcy-Scripting",
"Web-Scripting-Tools",
"Web-Mgmt-Service",
#other components
"NET-WCF-HTTP-Activation45",
"NET-WCF-TCP-PortSharing45",
"NET-WCF-TCP-Activation45",
"NET-WCF-Pipe-Activation45",
"NET-WCF-MSMQ-Activation45",
"NET-WCF-Services45",
"NET-Framework-45-Core",
"NET-Framework-45-ASPNET",
"NET-Framework-45-Features",
"WAS-Config-APIs",
"WAS-Process-Model",
"WAS",
"MSMQ-Services", 
"MSMQ-Server",
"MSMQ"

# dependance identifier
$dependance = "True"


While ($dependance -eq "True"){
    $dependance = "False"

foreach ($feature in $feature_list){
    $Installed = (Get-WindowsFeature $feature).Installed
    if ($Installed -eq "Installed"){
        Write-Host $feature " is already installed" -ForegroundColor Green
    }
    else{
        
        Write-Host "Process: " $feature " is installing" -ForegroundColor Yellow
        Install-WindowsFeature $feature 
        If (!$?){ $dependance = "True" }; 
    }

    }
}

Was this article helpful?

Related Articles