我需要使用 Powershell 启用两个 Windows 功能。但我不知道他们的名字或如何找到他们。
到目前为止,我已成功安装 IIS 并使用找到的脚本停止默认应用程序池 here .
function InstallFeature($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-ApplicationDevelopment
InstallFeature IIS-NetFxExtensibility
InstallFeature IIS-ISAPIExtensions
InstallFeature IIS-ISAPIFilter
InstallFeature IIS-ASPNET
InstallFeature IIS-WebServerManagementTools
InstallFeature IIS-ManagementConsole
InstallFeature IIS-ManagementScriptingTools
import-module WebAdministration
Stop-WebAppPool DefaultAppPool
解决方案
搜索:
Get-WindowsFeature *ASP*
Get-WindowsFeature *activation*
安装:
Add-WindowsFeature NET-Framework-45-ASPNET
Add-WindowsFeature NET-HTTP-Activation
请您参考如下方法:
对于较新的 Windows 客户端操作系统 (Windows 10/8.1/8),您不能使用 安装-WindowsFeature 因为这仅用于管理服务器上的功能。尝试使用它会导致错误消息:
Get-WindowsFeature : The target of the specified cmdlet cannot be a Windows client-based operating system.
有一个 DISM Powershell 模块,可用于查找和安装可选功能:
gcm -module DISM #List available commands
Get-WindowsOptionalFeature -online | ft #List all features and status
Enable-WindowsOptionalFeature -online -FeatureName NetFx3 -Source e:\Sources\sxs
在最后一条命令
-Source e:\Sources\sxs
仅当该功能需要引用源文件的安装介质时才需要(通常用于修复错误:0x800f081f 找不到源文件)。 .NET Framework 3.5 版似乎是唯一需要客户端操作系统的版本,但服务器操作系统上还有许多其他版本需要引用安装媒体的源代码。