我正在尝试编写一个脚本,以便在带有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位机器上。我已经查看了ProductListXml,其中包含此处的Web平台包列表,并将其复制并粘贴到存在的UrlRewrite2包的x64变体的引用下面。
<installer>
<id>20</id>
<languageId>en</languageId>
<architectures>
<x64/>
</architectures>
<eulaURL>
......
</installer>
有趣的是,有一个架构参数,但看看微软。网状物PlatformInstaller API似乎没有设置/访问它的方法。除了硬编码,有没有任何可能的方法告诉API获取64位版本?
我肯定是在64位机器上的64位powershell中运行这个程序的,但api会获取x86安装程序,这似乎与直觉相悖。是否有一些非常明显(且记录不足)的设置让我遗漏了?
作为Installers属性的Product类。我没有得到默认的安装程序,而是得到一个特定的安装程序(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
}
}