zoukankan      html  css  js  c++  java
  • 使用PowerShell 自动安装IIS 及自动部署网站

    执行环境:Windows Server 2012 R2

    安装iis核心代码,可自定义安装项

    注意这里不能使用add-windowsfeature  "Web-Filtering","Web-IP-Security"方式自定义安装,会抛出异常,我猜测是安装顺序的问题

    $iisInstallPro = "Web-Filtering","Web-IP-Security","Web-Url-Auth","Web-Windows-Auth","Web-Basic-Auth","Web-Http-Errors","Web-Static-Content","Web-Default-Doc","Web-Dir-Browsing","Web-Stat-Compression","Web-Http-Logging","Web-ODBC-Logging","Web-Mgmt-Console","Web-WHC","Web-Net-Ext","Web-Net-Ext45","Web-ASP","Web-Asp-Net","Web-Asp-Net45","Web-CGI","Web-ISAPI-Ext","Web-ISAPI-Filter","Web-WebSockets","Web-Includes","Web-AppInit";
    $features = get-windowsfeature web-*
    foreach($item in $features)
    {
      if($item.installed -eq $false -and $iisInstallPro -Match $item.Name)
      {
        Write-Host "安装:" $item.displayname
        $item | add-windowsfeature -WarningAction silentlyContinue
      }
    }

    自动安装IIS

    $features = get-windowsfeature web-*
    foreach($item in $features)
    {
      if($item.installed -eq $false)
      {
        Write-Host "安装:$item.displayname"
        $item | add-windowsfeature
      }
    }
    
    function RegisterAndEnableIsapi
    {
     $isapiPath ="$env:windirMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll"
      
      $isapiConfiguration = get-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed"
      if($null -eq $isapiConfiguration)
      {
        Write-Host "IIS尚未注册aspnet_isapi.dll"
        $tmpPath=""
       
       
        $tmpPath = "$env:windirMicrosoft.NETFrameworkv4.0.30319"
        
        set-location $tmpPath
        .aspnet_regiis.exe -i
        $isapiConfiguration = get-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed"
      }
      if($isapiConfiguration.Value -eq $false)
      {
          Write-Host "IIS已经注册过aspnet_isapi.dll,但未启用"
        set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed" -value true
        if(Is64Bit)
        { 
          set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$env:windirMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll']/@allowed" -value true
        }
        Write-Host "isapi已启用"
      }
      else
      {
          Write-Host "IIS已经注册过aspnet_isapi.dll,且已启用"
      }
    }
    
     RegisterAndEnableIsapi
    View Code

     自动部署网站     参考链接

    Import-Module WebAdministration
    New-Item –Path IIS:AppPoolsMyAppPool
    New-Website –Name MyWebApp –PhysicalPath D:apidd
    New-WebApplication -Name testApp -Site 'MyWebApp' -PhysicalPath D:apidd -ApplicationPool DefaultAppPool

      

    powershell自动安装iis,点击打开。打开之后如下图

    1.输入get-windowsfeature web* 查看已经安装过的IIS 功能(IIS的安装包全部以web开头的),结果如下(没有安装任何功能,安装过的前面[ ]会有X)。

    2.安装web-server,就是IIS 服务了。

    install-windowsfeature web-server 

    安装后会如果提示 Success 就是安装成功了。

  • 相关阅读:
    SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)
    HttpWatch工具简介及使用技巧
    橙色在网页设计运用:36个启发灵感的案例
    JS Date格式化为yyyyMMdd类字符串
    60款很酷的 jQuery 幻灯片演示和下载
    浅谈SQL Server中统计对于查询的影响
    C#创建Windows Service(Windows 服务)基础教程
    使用分页方式读取超大文件的性能试验
    240多个jQuey插件
    ASP.NET性能优化之负载均衡
  • 原文地址:https://www.cnblogs.com/GoCircle/p/11226683.html
Copyright © 2011-2022 走看看