如何更新Azure PowerShell?

14
我已经通过Gallery安装了Azure PowerShell 1.0.3(根据在Installing Azure PowerShell From The Gallery部分的说明)。我想要升级到最新版本,但不确定需要运行哪些命令。我尝试了下面的方法,但决定询问而不是潜在地破坏我的安装:
PS C:\Windows\system32> Install-Module AzureRM

You are installing the module(s) from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet.
Are you sure you want to install software from 'https://www.powershellgallery.com/api/v2/'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
WARNING: Version '1.0.3' of module 'AzureRM' is already installed at 'C:\Program
Files\WindowsPowerShell\Modules\AzureRM\1.0.3'. To delete version '1.0.3' and install version '1.1.0', run
Install-Module, and add the -Force parameter.

有人可以提供一个更新Azure PowerShell的脚本吗?

5个回答

17
你需要运行的命令已经包含在你发布的帮助文本中。使用 Install-Module -Force AzureRM 命令。可参见 -Force 标签
更新引导程序后,运行 Install-AzureRM 命令以安装新软件包。

针对更新版本(WMF > 4)的 PowerShell 编辑:

PowerShell 提供 Update-Module AzureRM 函数,可以执行类似于 Install-Module -Force AzureRM 命令的操作。如果你的本地环境中已经定义了 AzureRM 的函数,它会覆盖这些函数,因此你可能还想在 Install-Module 命令上使用 -AllowClobber 参数。
然而,这两个命令均不会更新当前环境,因此在运行 Install-AzureRM 命令之前,请检查是否加载了最新的 AzureRM 模块。例如,如果要从 1.0.1 更新到 1.0.3:
$ Get-Module AzureRM

ModuleType Version    Name         ExportedCommands
---------- -------    ----         ----------------
Script     1.0.1      AzureRM      {...}

$ Update-Module AzureRM

$ # This will still be old because we haven't imported the newer version.
$ (Get-Module AzureRM).Version.ToString() 
1.0.1

$ Remove-Module AzureRM
$ Import-Module AzureRM
$ (Get-Module AzureRM).Version.ToString() 
1.0.3

$ Install-AzureRM

或者,您可以在运行更新后打开新的 PowerShell 窗口。


就这些吗?在我提供的链接中,完整的安装脚本大约有6个命令。还需要运行其他命令吗? - GregGalloway
很多这些命令都与导入模块有关,因为你即将使用它。你可能需要继续这样做,但是是的,这就是你需要做的全部。你可以通过 Get-Module AzureRM 进行验证。 - Jeremy Fortune
实际上,在刷新引导程序后,你应该再次运行 Install-AzureRM。好的,我会更新答案。 - Jeremy Fortune

10

看起来命令有点变化,我必须使用Install-Module -Force AzureRM -AllowClobber来更新它。


1
最可靠的方式似乎是:
下载最新的MSI文件并运行。https://github.com/Azure/azure-powershell/releases 我知道您要求一个脚本版本...但我没有找到各种脚本答案令人满意。(我不想要并存安装;Install-AzureRM未找到等)。

1
我尝试了答案中列出的其他所有命令,但都没有起作用,所以我只能使用MSI下载并安装最新版本。 :( - Rajesh Swarnkar

0

我使用:

$azureRMs = Get-Module
foreach($azureRM in $azureRMs)
    {
    if($azureRM.name -like "AzureRM*" )
        {
        write-host "removing" $azureRM
        remove-Module -Name $azureRM
        Uninstall-Module -Name $azureRM
        }
    }
Install-Module azureRM

0

最好且简单的方法是从官方链接进入并查找高亮部分。 该链接将提供AzurePowershell最新版本的MSI安装包。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接