我是PowerShell的新手,但基本上我希望能够在powershell脚本中通过componentsnet安装IIS组件。我应该能够查看这些名称,并将其插入Add-WindowsFeatures命令。期待你的回答。我在Windows Server 2008 R2上执行此操作。谢谢!
答案 0 :(得分:0)
向后兼容的方式(至少返回到Win7)是列出所有可用功能,并使用dism /online /Get-Features
(或Win 10上的Get-WindowsOptionalFeature -online | ft
)查看安装状态。一旦找到所需的功能(案例很重要),只需让ocsetup
(或Win10上的Enable-WindowsOptionalFeature
)为您完成工作
# 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