代码之家  ›  专栏  ›  技术社区  ›  Lloyd Powell binku

安装IIS作为Octopus Deploy中的一个步骤

  •  1
  • Lloyd Powell binku  · 技术社区  · 7 年前

    Octopus Deployment 如果目标上没有安装IIS,它将安装IIS,但我找不到任何内容。如果目前没有任何东西,是否有一个powershell脚本可以用于添加 Web Server (IIS) 机器的角色/功能?

    这将使启动安装了最少功能的新虚拟机更加容易,然后在部署特定应用程序时,它们可以管理是否需要IIS,而不是手动将其添加到适当的计算机。

    提前谢谢!

    2 回复  |  直到 7 年前
        1
  •  3
  •   HariHaran    7 年前

    你可以使用 Enable-WindowsOptionalFeature Install-WindowsFeature here

    下面是一个检查是否安装了IIS的示例,如果没有安装,则安装

     if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
            Write-Host "IIS is installed on $vm"
        } 
        else {
            Write-Host "IIS is not installed on $vm"
            Write-Host "Installing IIS.."
            Install-WindowsFeature -name Web-Server -IncludeManagementTools
        }
    
        2
  •  1
  •   Lloyd Powell binku    7 年前

    我在翻阅了章鱼的模板后找到了一个解决方案, WesleySSmith 有一个名为 Windows - Ensure Features Installed IIS-WebServer .

    对于PowerShell狂热者来说,这一步背后的脚本如下:

    $requiredFeatures = $OctopusParameters['WindowsFeatures'].split(",") | foreach { 
    
    $_.trim() }
    if(! $requiredFeatures) {
        Write-Output "No required Windows Features specified..."
        exit
    }
    $requiredFeatures | foreach { $feature = DISM.exe /ONLINE /Get-FeatureInfo /FeatureName:$_; if($feature -like "*Feature name $_ is unknown*") { throw $feature } }
    
    Write-Output "Retrieving all Windows Features..."
    $allFeatures = DISM.exe /ONLINE /Get-Features /FORMAT:List | Where-Object { $_.StartsWith("Feature Name") -OR $_.StartsWith("State") } 
    $features = new-object System.Collections.ArrayList
    for($i = 0; $i -lt $allFeatures.length; $i=$i+2) {
        $feature = $allFeatures[$i]
        $state = $allFeatures[$i+1]
        $features.add(@{feature=$feature.split(":")[1].trim();state=$state.split(":")[1].trim()}) | OUT-NULL
    }
    
    Write-Output "Checking for missing Windows Features..."
    $missingFeatures = new-object System.Collections.ArrayList
    $features | foreach { if( $requiredFeatures -contains $_.feature -and $_.state -eq 'Disabled') { $missingFeatures.add($_.feature) | OUT-NULL } }
    if(! $missingFeatures) {
        Write-Output "All required Windows Features are installed"
        exit
    }
    Write-Output "Installing missing Windows Features..."
    $featureNameArgs = ""
    $missingFeatures | foreach { $featureNameArgs = $featureNameArgs + " /FeatureName:" + $_ }
    $dism = "DISM.exe"
    IF ($SuppressReboot)
    {
        $arguments = "/NoRestart "
    }
    ELSE
    {
        $arguments = ""
    }
    $arguments = $arguments + "/ONLINE /Enable-Feature $featureNameArgs"
    IF ($Source)
    {
        if (!(Test-Path $Source)) {
            throw "Could not find the file $Source or access denied"
        }
        $arguments = $arguments + " /Source:$Source"
    }
    Write-Output "Calling DISM with arguments: $arguments"
    start-process -NoNewWindow $dism $arguments
    
    推荐文章