目标是在.NET开发环境的新Windows Workstation(如Windows 10)上自动启用IIS。我意识到可以编写Powershell脚本来做这样的事情,但我不知道从哪里开始。自动安装IIS
我意识到我可以轻松进入控制面板并在那里启用服务,但运行脚本来执行此操作似乎更有效。
示例脚本将如何在Powershell中运行以启用IIS?
目标是在.NET开发环境的新Windows Workstation(如Windows 10)上自动启用IIS。我意识到可以编写Powershell脚本来做这样的事情,但我不知道从哪里开始。自动安装IIS
我意识到我可以轻松进入控制面板并在那里启用服务,但运行脚本来执行此操作似乎更有效。
示例脚本将如何在Powershell中运行以启用IIS?
服务器操作系统的
在Windows Server,你可以运行下面的命令来自动安装IIS的:
#-LogPath can be added if you want a log to be created of the installation
#-Restart can be added if you want to auto restart after installation
Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server
下面是从PowerShell的角度来看的IIS功能的名称:
Display Name Name
------------ ----
[ ] Web Application Proxy Web-Application-Proxy
[ ] Web Server (IIS) Web-Server
[ ] Web Server Web-WebServer
[ ] Common HTTP Features Web-Common-Http
[ ] Default Document Web-Default-Doc
[ ] Directory Browsing Web-Dir-Browsing
[ ] HTTP Errors Web-Http-Errors
[ ] Static Content Web-Static-Content
[ ] HTTP Redirection Web-Http-Redirect
[ ] WebDAV Publishing Web-DAV-Publishing
[ ] Health and Diagnostics Web-Health
[ ] HTTP Logging Web-Http-Logging
[ ] Custom Logging Web-Custom-Logging
[ ] Logging Tools Web-Log-Libraries
[ ] ODBC Logging Web-ODBC-Logging
[ ] Request Monitor Web-Request-Monitor
[ ] Tracing Web-Http-Tracing
[ ] Performance Web-Performance
[ ] Static Content Compression Web-Stat-Compression
[ ] Dynamic Content Compression Web-Dyn-Compression
[ ] Security Web-Security
[ ] Request Filtering Web-Filtering
[ ] Basic Authentication Web-Basic-Auth
[ ] Centralized SSL Certificate Support Web-CertProvider
[ ] Client Certificate Mapping Authentic... Web-Client-Auth
[ ] Digest Authentication Web-Digest-Auth
[ ] IIS Client Certificate Mapping Authe... Web-Cert-Auth
[ ] IP and Domain Restrictions Web-IP-Security
[ ] URL Authorization Web-Url-Auth
[ ] Windows Authentication Web-Windows-Auth
[ ] Application Development Web-App-Dev
[ ] .NET Extensibility 3.5 Web-Net-Ext
[ ] .NET Extensibility 4.5 Web-Net-Ext45
[ ] Application Initialization Web-AppInit
[ ] ASP Web-ASP
[ ] ASP.NET 3.5 Web-Asp-Net
[ ] ASP.NET 4.5 Web-Asp-Net45
[ ] CGI Web-CGI
[ ] ISAPI Extensions Web-ISAPI-Ext
[ ] ISAPI Filters Web-ISAPI-Filter
[ ] Server Side Includes Web-Includes
[ ] WebSocket Protocol Web-WebSockets
[ ] FTP Server Web-Ftp-Server
[ ] FTP Service Web-Ftp-Service
[ ] FTP Extensibility Web-Ftp-Ext
[ ] Management Tools Web-Mgmt-Tools
[ ] IIS Management Console Web-Mgmt-Console
[ ] IIS 6 Management Compatibility Web-Mgmt-Compat
[ ] IIS 6 Metabase Compatibility Web-Metabase
[ ] IIS 6 Management Console Web-Lgcy-Mgmt-Console
[ ] IIS 6 Scripting Tools Web-Lgcy-Scripting
[ ] IIS 6 WMI Compatibility Web-WMI
[ ] IIS Management Scripts and Tools Web-Scripting-Tools
[ ] Management Service Web-Mgmt-Service
[ ] IIS Hostable Web Core Web-WHC
用“逗号”参数分隔您希望安装的每个功能。例如:
Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server, Web-Mgmt-Tools, Web-Security
客户端操作系统的
在Windows 8.1+可以使用Get-WindowsOptionalFeature
和Enable-WindowsOptionalFeature
安装IIS。
运行以下你可以从PowerShell中的观点得到的IIS功能的名称:通过运行类似下面的什么
PS C:\> Get-WindowsOptionalFeature -online | Where {$_.FeatureName -like 'IIS*'} | Sort FeatureName | Format-Table
FeatureName State
----------- -----
IIS-ApplicationDevelopment Disabled
IIS-ApplicationInit Disabled
IIS-ASP Disabled
IIS-ASPNET Disabled
IIS-ASPNET45 Disabled
IIS-BasicAuthentication Disabled
IIS-CertProvider Disabled
IIS-CGI Disabled
IIS-ClientCertificateMappingAuthentication Disabled
IIS-CommonHttpFeatures Disabled
IIS-CustomLogging Disabled
IIS-DefaultDocument Disabled
IIS-DigestAuthentication Disabled
IIS-DirectoryBrowsing Disabled
IIS-FTPExtensibility Disabled
IIS-FTPServer Disabled
IIS-FTPSvc Disabled
IIS-HealthAndDiagnostics Disabled
IIS-HostableWebCore Disabled
IIS-HttpCompressionDynamic Disabled
IIS-HttpCompressionStatic Disabled
IIS-HttpErrors Disabled
IIS-HttpLogging Disabled
IIS-HttpRedirect Disabled
IIS-HttpTracing Disabled
IIS-IIS6ManagementCompatibility Disabled
IIS-IISCertificateMappingAuthentication Disabled
IIS-IPSecurity Disabled
IIS-ISAPIExtensions Disabled
IIS-ISAPIFilter Disabled
IIS-LegacyScripts Disabled
IIS-LegacySnapIn Disabled
IIS-LoggingLibraries Disabled
IIS-ManagementConsole Disabled
IIS-ManagementScriptingTools Disabled
IIS-ManagementService Disabled
IIS-Metabase Disabled
IIS-NetFxExtensibility Disabled
IIS-NetFxExtensibility45 Disabled
IIS-ODBCLogging Disabled
IIS-Performance Disabled
IIS-RequestFiltering Disabled
IIS-RequestMonitor Disabled
IIS-Security Disabled
IIS-ServerSideIncludes Disabled
IIS-StaticContent Disabled
IIS-URLAuthorization Disabled
IIS-WebDAV Disabled
IIS-WebServer Disabled
IIS-WebServerManagementTools Disabled
IIS-WebServerRole Disabled
IIS-WebSockets Disabled
IIS-WindowsAuthentication Disabled
IIS-WMICompatibility Disabled
到Windows Server类似,您可以安装上面的功能(你可以通过使用逗号值在FeatureName参数分开安装多个功能:
#you can add -NoRestart to prevent automatic restarting (if required)
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Webserver
希望这有助于
这非常有帮助!谢谢! – micah
我认为上面这段代码也会在Windows 7/8/10上运行,对不对?运行'.ps1',以Admin身份运行,我使用'Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server,Web-Mgmt-Tools,Web-Security'创建的,我转到控制面板中的Windows功能窗口>程序和功能,它不会将IIS显示为已安装/启用。有什么我应该做的,使这项工作在常规的Windows? – micah
我的初步答案只适用于Windows服务器。我刚刚编辑并为客户端操作系统添加了一个部分。客户端操作系统部分只能在Windows 8.1+上运行。 –
有关IIS相关功能的完整列表以及有关Install-WindowsFeature
cmdlet参数的更多信息,请参见Tyler Helder's helpful answer; 这个的答案是比较概念化的。
有一个很好的机会,ServerManager
PowerShell的模块自带的Windows 服务器 OS预装(W2K8R2 +;注意客户操作系统require a different method):
如果是这样,你可以安装IIS作为如下:
Add-WindowsFeature Web-Server
Add-WindowsFeature
,因为W2K8R2目前,更名为Install-WindowsFeature
在W2K12R2,但Add-WindowsFeature
被保留为别名,所以它在这两个版本的作品。
要列表所有服务器功能及其安装状态,运行Get-WindowsFeature
。
需要注意的是从必须提供作为参数传递给Add-WindowsFeature
/Install-WindowsFeature
的cmdlet的Name
列中的值,而DisplayName column
往往含有感兴趣的关键字。
案例:要发现其显示名称中包含“IIS”所有功能 - 并由此发现了IIS的功能的名称是Web-Server
- 运行(PSv3 +):
Get-WindowsFeature | ? DisplayName -like *IIS*
为什么不是谷歌?这是从哪里开始,而不是在这里。 –
我一直在使用Google几天/周。 Powershell脚本不适用于这类任务,这让我感到困惑。大多数文章使用Powershell本身而不是脚本。 – micah
“Powershell脚本”和“Powershell本身”有什么区别? – jscott