【问题标题】:powershell doesn't install AzurePowerShellpowershell 不安装 AzurePowerShell
【发布时间】:2014-06-05 10:34:52
【问题描述】:

我在互联网上找到了安装 WindowsAzurePowerShell 的脚本,但它不起作用:

    [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()

我看到异常:

使用“2”参数调用“DownloadInstallerFile”的异常:“传递给此方法的 InstallerContext 需要非 Null InstallerFile。” 在 C:\Users\test.ps1:18 char:5 + $InstallManager.DownloadInstallerFile($installerContext, [ref]$failureReason ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : InvalidOperationException

所以。它是如何解决的?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我在下面整理的这个示例并没有按照您尝试的方式安装该软件包,而是下载 WebPi CLI,提取 zip 并在提升的提示符下运行它,然后返回退出代码。我认为这将完成工作,并且可以在所有可能未安装 WebPI 的机器上复制,因为您可以将文件放在共享上并在多台计算机上运行。

    $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
    

    【讨论】:

      猜你喜欢
      • 2020-04-26
      • 2022-01-07
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 2018-01-15
      • 2021-06-02
      相关资源
      最近更新 更多