我正在尝试编写一个脚本,以在带有 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 位机器上。我查看了包含 Web 平台包列表的 ProductList Xml here ,我已经复制并粘贴到 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 安装程序似乎非常违反直觉。是否有一些我遗漏的非常明显(且记录很少)的设置?
最佳答案
作为 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
}
}
关于windows - 使用带有 Web 平台安装程序 API 的 Powershell 仅在 64 位计算机上获取 x86 安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31060846/