0
votes

I found script on internet, which install WindowsAzurePowerShell, but it doesn't work:

    [reflection.assembly]::LoadWithPartialName("Microsoft.Web.PlatformInstaller") | Out-Null

    $ProductManager = New-Object Microsoft.Web.PlatformInstaller.ProductManager
    $ProductManager.Load()
    $product = $ProductManager.Products | Where { $_.ProductId -eq "WindowsAzurePowerShell" }

    $InstallManager = New-Object Microsoft.Web.PlatformInstaller.InstallManager

    $Language = $ProductManager.GetLanguage("en")
    $installertouse = $product.GetInstaller($Language)

    $installer = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Installer]'
    $installer.Add($installertouse)
    $InstallManager.Load($installer)

    $failureReason=$null
    foreach ($installerContext in $InstallManager.InstallerContexts) {
        $InstallManager.DownloadInstallerFile($installerContext, [ref]$failureReason)
    }
    $InstallManager.StartInstallation()

I see exception:

Exception calling "DownloadInstallerFile" with "2" argument(s): "The InstallerContext passed to this method requires a non-Null InstallerFile." At C:\Users\test.ps1:18 char:5 + $InstallManager.DownloadInstallerFile($installerContext, [ref]$failureReason ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : InvalidOperationException

So. How it's fixed?

1

1 Answers

1
votes

This example I have put together below doesn't go about installing that package the way you where attempting but instead downloads the WebPi CLI, extracts the zip and runs it in an elevated prompt then returns an exit code. I think this will get the job done and can be reproduced on all boxes that may not have the WebPI installed as you can place the file on a share and run this across many computers.

$SourcePath = "http://www.iis.net/community/files/webpi/webpicmd_x86.zip"
$DestinationPath = "c:\Temp\webpicmd_x86.zip"
$ExtractionPath = "c:\Temp\WebPICmd"
$CWebPiCmdLineTool = "$ExtractionPath\WebpiCmdLine.exe"
Import-Module BitsTransfer

Start-BitsTransfer -Source $SourcePath -Destination $DestinationPath

New-Item -Path C:\Temp -Name WebPICmd -ItemType directory | Out-Null

$shell = new-object -com shell.application
$zip = $shell.NameSpace($DestinationPath)
foreach($item in $zip.items())
{
    $shell.Namespace($ExtractionPath).copyhere($item)
}

$InstallWebPiPackages = Start-Process -FilePath $CWebPiCmdLineTool -ArgumentList "/Products:WindowsAzurePowerShell" -Verb "RunAs" -Wait -PassThru
$InstallWebPiPackages.ExitCode