4

我正在尝试编写一个脚本来使用 IIS 8 和 Web 平台安装程序 5 在 x64 Windows Server 2012 R2 上自动安装应用程序请求路由包。我已经复制了我在下面使用的代码:

Try {
[reflection.assembly]::LoadWithPartialName("Microsoft.Web.PlatformInstaller") | Out-Null
$ProductManager = New-Object Microsoft.Web.PlatformInstaller.ProductManager
$ProductManager.Load()

$product = $ProductManager.Products | Where { $_.ProductId -eq "ARRv3_0" }


#Get an instance of InstallManager class to perform package install
$InstallManager = New-Object Microsoft.Web.PlatformInstaller.InstallManager

$installer = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Installer]'

$Language = $ProductManager.GetLanguage("en")

#Get dependencies
$deplist = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Product]'
$deplist.add($product)
$deps = $product.getMissingDependencies($deplist)
foreach ($dep in $deps) { 

        Write-Host "$($dep.GetInstaller($Language))"

        $Installer.Add($dep.GetInstaller($Language))
        Write-Host "Dependency $($dep.Title) not found..."
}

$installer.Add($product.Installers[1])
$InstallManager.Load($installer)

#Download the installer package
$failureReason=$null
foreach ($installerContext in $InstallManager.InstallerContexts) {
    $InstallManager.DownloadInstallerFile($installerContext, [ref]$failureReason)

    Write-Host $($installerContext)
}

$InstallManager.StartSynchronousInstallation()

notepad $product.Installers[1].LogFiles

Write-Host "Opening logs at $($product.Installers[1].LogFiles)"
Write-Host "Installation finished"

}
Catch {
    Write-Error "FATAL ERROR! $($_)"
}

Finally {
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
} 

ARRv3_0 有两个依赖项,ExternalCache 和 UrlRewrite2。

但是,当我尝试使用以下方式拉动安装程序时:

$Language = $ProductManager.GetLanguage("en")
$installer.Add($dep.GetInstaller($Language))

(其中 $dep 是对产品的引用)它只获取 x86 版本,不会安装在 64 位机器上。我查看了 ProductList Xml,其中包含此处的 Web 平台包列表,并且我已经复制并粘贴到存在的 UrlRewrite2 包的 x64 变体下面。

<installer>
    <id>20</id>
    <languageId>en</languageId>
    <architectures>
        <x64/>
    </architectures>
    <eulaURL>
    ......
</installer>

有趣的是,有一个架构参数,但是查看Microsoft.Web.PlatformInstaller API似乎没有设置/访问它的方法。除了硬编码,还有什么方法可以告诉 API 获取 64 位版本吗?

我肯定会在 64 位机器上的 64 位 powershell 中运行它,但是 api 会获取 x86 安装程序似乎非常违反直觉。是否有一些我遗漏的非常明显(并且记录不充分)的设置?

4

1 回答 1

0

Product 类作为 Installers 属性。我没有获得默认安装程序,而是获得了一个特定的安装程序(64 位)并将其添加到作为参数传递给 InstallManager 的通用安装程序列表中。这是片段。

$installers = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Installer]'

foreach($i in $product.Installers)
{        
        if($i.InstallerFile.InstallerUrl.ToString().ToLower().EndsWith("_amd64.msi"))
        {            
            $i.InstallerFile
            $installers.Add($i)
            break
        }
}  
于 2015-10-30T04:32:39.377 回答