我试图编写一个脚本来自动在带有IIS 8和Web平台安装程序5的x64 Windows Server 2012 R2上安装应用程序请求路由包。我已经复制了代码I&#39 ; m使用以下:
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平台软件包列表here的ProductList Xml,并且我已经复制并粘贴了UrlRewrite2软件包x64变体的出现位置。< / p>
<installer>
<id>20</id>
<languageId>en</languageId>
<architectures>
<x64/>
</architectures>
<eulaURL>
......
</installer>
有趣的是,有一个架构参数,但是看Microsoft.Web.PlatformInstaller API似乎并不是设置/访问它的方法。除了硬编码之外,还有什么方法可以告诉API取代64位版本吗?
我确实在64位机器上的64位PowerShell中运行它,但似乎非常反直觉api会获取x86安装程序。是否有一些令人难以置信的明显(并且记录不完整)的设置我不知道?
答案 0 :(得分: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
}
}