Using Powershell APIs W / Web Platform Installer to only install x86 installers on a 64-bit machine
I am trying to write a script to automate the installation of an Application Request Routing Package on x64 Windows Server 2012 R2 with IIS 8 and Web Platform 5 installer. I have reproduced the code I am using below
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 has two dependencies: ExternalCache and UrlRewrite2.
However, when I try to pull the installers using:
$Language = $ProductManager.GetLanguage("en")
$installer.Add($dep.GetInstaller($Language))
(where $ dep is the product link), it only fetches the x86 version which will not be installed on a 64 bit machine. I looked at the ProductList Xml which lists the web platform packages here and I copied and pasted below the appearance of the x64 variant of the UrlRewrite2 package that exists.
<installer>
<id>20</id>
<languageId>en</languageId>
<architectures>
<x64/>
</architectures>
<eulaURL>
......
</installer>
Interestingly there is an architecture parameter, but looking at the Microsoft.Web.PlatformInstaller API there seems to be no way to set / access it. Apart from hardcoding, is there any possible way to tell the API to get 64-bit instead?
I am definitely running this in 64-bit PowerShell on a 64-bit machine, but it seems incredibly counter-intuitive that the api will get x86 installers. Are there some incredibly obvious (and poorly documented) settings that I am missing?
source to share
Product class as the Installers property. Instead of getting the default installer, I get the specific installer (64 bit) and add it to the general installers list, which is passed as an argument to InstallManager. Here is a snippet.
$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
}
}
source to share