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

前端之家收集整理的这篇文章主要介绍了Windows – PowerShell脚本自动安装IIS 7及更高版本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是一个完整的新手.我需要的是一个Power Shell脚本,可以自动执行IIS7或更高版本的安装过程.我对角色服务有一定的配置.在这方面的任何帮助是赞赏.
我发现以下博客很有用,从使用帮助的某些更改,我能够从电源shell安装IIS与自定义角色服务.我有代码在这里和博客链接是:

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

  1. # --------------------------------------------------------------------
  2. # Checking Execution Policy
  3. # --------------------------------------------------------------------
  4. #$Policy = "Unrestricted"
  5. $Policy = "RemoteSigned"
  6. If ((get-ExecutionPolicy) -ne $Policy) {
  7. Write-Host "Script Execution is disabled. Enabling it now"
  8. Set-ExecutionPolicy $Policy -Force
  9. Write-Host "Please Re-Run this script in a new powershell enviroment"
  10. Exit
  11. }
  12.  
  13. # --------------------------------------------------------------------
  14. # Define the variables.
  15. # --------------------------------------------------------------------
  16. $InetPubRoot = "D:\Inetpub"
  17. $InetPubLog = "D:\Inetpub\Log"
  18. $InetPubWWWRoot = "D:\Inetpub\WWWRoot"
  19.  
  20. # --------------------------------------------------------------------
  21. # Loading Feature Installation Modules
  22. # --------------------------------------------------------------------
  23. Import-Module ServerManager
  24.  
  25. # --------------------------------------------------------------------
  26. # Installing IIS
  27. # --------------------------------------------------------------------
  28. 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
  29.  
  30. # --------------------------------------------------------------------
  31. # Loading IIS Modules
  32. # --------------------------------------------------------------------
  33. Import-Module WebAdministration
  34.  
  35. # --------------------------------------------------------------------
  36. # Creating IIS Folder Structure
  37. # --------------------------------------------------------------------
  38. New-Item -Path $InetPubRoot -type directory -Force -ErrorAction SilentlyContinue
  39. New-Item -Path $InetPubLog -type directory -Force -ErrorAction SilentlyContinue
  40. New-Item -Path $InetPubWWWRoot -type directory -Force -ErrorAction SilentlyContinue
  41.  
  42. # --------------------------------------------------------------------
  43. # Copying old WWW Root data to new folder
  44. # --------------------------------------------------------------------
  45. $InetPubOldLocation = @(get-website)[0].physicalPath.ToString()
  46. $InetPubOldLocation = $InetPubOldLocation.Replace("%SystemDrive%",$env:SystemDrive)
  47. Copy-Item -Path $InetPubOldLocation -Destination $InetPubRoot -Force -Recurse
  48.  
  49. # --------------------------------------------------------------------
  50. # Setting directory access
  51. # --------------------------------------------------------------------
  52. $Command = "icacls $InetPubWWWRoot /grant BUILTIN\IIS_IUSRS:(OI)(CI)(RX) BUILTIN\Users:(OI)(CI)(RX)"
  53. cmd.exe /c $Command
  54. $Command = "icacls $InetPubLog /grant ""NT SERVICE\TrustedInstaller"":(OI)(CI)(F)"
  55. cmd.exe /c $Command
  56.  
  57. # --------------------------------------------------------------------
  58. # Setting IIS Variables
  59. # --------------------------------------------------------------------
  60. #Changing Log Location
  61. $Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:$InetPubLog"
  62. cmd.exe /c $Command
  63. $Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:$InetPubLog"
  64. cmd.exe /c $Command
  65. $Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:$InetPubLog"
  66. cmd.exe /c $Command
  67.  
  68. #Changing the Default Website location
  69. Set-ItemProperty 'IIS:\Sites\Default Web Site' -name physicalPath -value $InetPubWWWRoot
  70.  
  71. # --------------------------------------------------------------------
  72. # Checking to prevent common errors
  73. # --------------------------------------------------------------------
  74. If (!(Test-Path "C:\inetpub\temp\apppools")) {
  75. New-Item -Path "C:\inetpub\temp\apppools" -type directory -Force -ErrorAction SilentlyContinue
  76. }
  77.  
  78. # --------------------------------------------------------------------
  79. # Deleting Old WWWRoot
  80. # --------------------------------------------------------------------
  81. Remove-Item $InetPubOldLocation -Recurse -Force
  82.  
  83. # --------------------------------------------------------------------
  84. # Resetting IIS
  85. # --------------------------------------------------------------------
  86. $Command = "IISRESET"
  87. Invoke-Expression -Command $Command

猜你在找的Windows相关文章