目標是在.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