我是 powershell 的新手,但基本上我希望能够在 powershell 脚本中通过 componenet 安装 IIS 组件。我应该能够查看这些名称并将其插入 Add-WindowsFeatures 命令。期待您的回答。我在 Windows Server 2008 R2 上执行此操作。谢谢!
问问题
1954 次
1 回答
0
一种向后兼容的方式(至少回到 Win7)是列出所有可用的功能并查看安装状态dism /online /Get-Features
(或Get-WindowsOptionalFeature -online | ft
在 Win 10 上)。一旦找到您想要的功能(大小写很重要),就让ocsetup
(或Enable-WindowsOptionalFeature
在 Win10 上)为您完成工作
# install windows features function
function InstallFeature($name){
$winversion = (Get-CimInstance Win32_OperatingSystem).version;
# Write-Host "detected $winversion"
if ($winversion -like "10.*"){
Write-Host "adding Windows 10 feature $name";
Enable-WindowsOptionalFeature -online -FeatureName $name
} else {
Write-Host "adding Windows 7 feature $name";
cmd /c "ocsetup $name /passive"
}
}
InstallFeature IIS-WebServerRole
InstallFeature IIS-WebServer
InstallFeature IIS-CommonHttpFeatures
InstallFeature IIS-DefaultDocument
InstallFeature IIS-DirectoryBrowsing
InstallFeature IIS-HttpErrors
InstallFeature IIS-HttpRedirect
InstallFeature IIS-StaticContent
InstallFeature IIS-HealthAndDiagnostics
InstallFeature IIS-CustomLogging
InstallFeature IIS-HttpLogging
InstallFeature IIS-HttpTracing
InstallFeature IIS-LoggingLibraries
InstallFeature IIS-Security
InstallFeature IIS-RequestFiltering
InstallFeature IIS-WindowsAuthentication
InstallFeature IIS-IPSecurity
InstallFeature IIS-ApplicationDevelopment
InstallFeature IIS-NetFxExtensibility
InstallFeature IIS-ISAPIExtensions
InstallFeature IIS-ISAPIFilter
InstallFeature IIS-ASPNET
InstallFeature IIS-CGI
InstallFeature IIS-Performance
InstallFeature IIS-HttpCompressionStatic
InstallFeature IIS-HttpCompressionDynamic
InstallFeature IIS-WebServerManagementTools
InstallFeature IIS-ManagementConsole
InstallFeature IIS-ManagementScriptingTools
InstallFeature IIS-Metabase
于 2015-04-10T15:59:20.663 回答