加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows – PowerShell脚本自动安装IIS 7及更高版本

发布时间:2020-12-13 20:15:03 所属栏目:Windows 来源:网络整理
导读:我是一个完整的新手.我需要的是一个Power Shell脚本,可以自动执行IIS7或更高版本的安装过程.我对角色服务有一定的配置.在这方面的任何帮助是赞赏. 我发现以下博客很有用,从使用帮助的某些更改,我能够从电源shell安装IIS与自定义角色服务.我有代码在这里和博
我是一个完整的新手.我需要的是一个Power Shell脚本,可以自动执行IIS7或更高版本的安装过程.我对角色服务有一定的配置.在这方面的任何帮助是赞赏.
我发现以下博客很有用,从使用帮助的某些更改,我能够从电源shell安装IIS与自定义角色服务.我有代码在这里和博客的链接是:

http://www.ithassle.nl/2010/09/powershell-script-to-install-and-configure-iis7-5/#codesyntax_1

# --------------------------------------------------------------------
# Checking Execution Policy
# --------------------------------------------------------------------
#$Policy = "Unrestricted"
$Policy = "RemoteSigned"
If ((get-ExecutionPolicy) -ne $Policy) {
  Write-Host "Script Execution is disabled. Enabling it now"
  Set-ExecutionPolicy $Policy -Force
  Write-Host "Please Re-Run this script in a new powershell enviroment"
  Exit
}

# --------------------------------------------------------------------
# Define the variables.
# --------------------------------------------------------------------
$InetPubRoot = "D:Inetpub"
$InetPubLog = "D:InetpubLog"
$InetPubWWWRoot = "D:InetpubWWWRoot"

# --------------------------------------------------------------------
# Loading Feature Installation Modules
# --------------------------------------------------------------------
Import-Module ServerManager 

# --------------------------------------------------------------------
# Installing IIS
# --------------------------------------------------------------------
Add-WindowsFeature -Name Web-Common-Http,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Http-Logging,Web-Request-Monitor,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Performance,Web-Mgmt-Console,Web-Mgmt-Compat,RSAT-Web-Server,WAS -IncludeAllSubFeature

# --------------------------------------------------------------------
# Loading IIS Modules
# --------------------------------------------------------------------
Import-Module WebAdministration

# --------------------------------------------------------------------
# Creating IIS Folder Structure
# --------------------------------------------------------------------
New-Item -Path $InetPubRoot -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubLog -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubWWWRoot -type directory -Force -ErrorAction SilentlyContinue

# --------------------------------------------------------------------
# Copying old WWW Root data to new folder
# --------------------------------------------------------------------
$InetPubOldLocation = @(get-website)[0].physicalPath.ToString()
$InetPubOldLocation =  $InetPubOldLocation.Replace("%SystemDrive%",$env:SystemDrive)
Copy-Item -Path $InetPubOldLocation -Destination $InetPubRoot -Force -Recurse

# --------------------------------------------------------------------
# Setting directory access
# --------------------------------------------------------------------
$Command = "icacls $InetPubWWWRoot /grant BUILTINIIS_IUSRS:(OI)(CI)(RX) BUILTINUsers:(OI)(CI)(RX)"
cmd.exe /c $Command
$Command = "icacls $InetPubLog /grant ""NT SERVICETrustedInstaller"":(OI)(CI)(F)"
cmd.exe /c $Command

# --------------------------------------------------------------------
# Setting IIS Variables
# --------------------------------------------------------------------
#Changing Log Location
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:$InetPubLog"
cmd.exe /c $Command

#Changing the Default Website location
Set-ItemProperty 'IIS:SitesDefault Web Site' -name physicalPath -value $InetPubWWWRoot

# --------------------------------------------------------------------
# Checking to prevent common errors
# --------------------------------------------------------------------
If (!(Test-Path "C:inetpubtempapppools")) {
  New-Item -Path "C:inetpubtempapppools" -type directory -Force -ErrorAction SilentlyContinue
}

# --------------------------------------------------------------------
# Deleting Old WWWRoot
# --------------------------------------------------------------------
Remove-Item $InetPubOldLocation -Recurse -Force

# --------------------------------------------------------------------
# Resetting IIS
# --------------------------------------------------------------------
$Command = "IISRESET"
Invoke-Expression -Command $Command

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读