【问题标题】:'New-AzureStorageContext' is not recognized'New-AzureStorageContext' 无法识别
【发布时间】:2019-05-09 16:50:24
【问题描述】:

我正在尝试运行可在同事计算机上运行的 PowerShell 脚本,但在我的这一行上运行失败:

Set-Variable -Name StorageContext -Value (New-AzureStorageContext -ConnectionString $storageConnectionString)

我的错误是:

New-AzureStorageContext :术语“New-AzureStorageContext”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者路径是否 包括,验证路径是否正确,然后重试。 在 C:\Users\dlogg\Documents\Repos\sd2\PowerShell Scripts\Eco\AddEco.ps1:22 char:43 + Set-Variable -Name StorageContext -Value (New-AzureStorageContext -ConnectionStr...

我已经确认我拥有 PowerShell v.3,并且我已经从 Web PI 安装了带有 Microsoft Azure SDK 和 Microsoft Azure PowerShell(独立)的 Azure PowerShell。我需要安装什么才能使用它?

http://msdn.microsoft.com/en-us/library/azure/dn495246.aspx

更新:根据以下请求,我已包含Get-Module 的输出:

ModuleType Name                                ExportedCommands                                                                                                                                              
---------- ----                                ----------------                                                                                                                                              
Script     Common                              {Fetch, Get-BlobContainer, Get-ConfigurationFileName, Get-DeploymentTenantListFileName...}                                                                    
Script     ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                                                                                           
Manifest   Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                                                                                            
Manifest   Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}    

【问题讨论】:

    标签: powershell azure


    【解决方案1】:

    我和你有同样的问题。 我的问题是使用了错误的命令:“AzureStorageContext”。它应该是“AzStorageContext”

    【讨论】:

    • 正如您所建议的,对于 PowerShell Core Az-library,命令是 New-AzStorageContext。因此,New-AzureStorageContext 对某些用户有效,对某些用户无效。
    • 我试图从发布管道中的 Azure Powershell 任务的上下文中执行这些命令。原来 AzStorageContext 是我需要使用的,而不是 AzureStorageContext。你的回答帮助我发现了这一点。谢谢!
    • 我想我爱你!离开 AzureRm 后,我一直在努力更新旧脚本。如此简单的东西却能逃避检查。
    【解决方案2】:

    您尚未加载 Azure PowerShell 模块(因此您拥有的列表中缺少它)。当您安装 Cmdlet 时,您还将获得一个新的快捷方式“Microsoft Azure Powershell”,它将自动为您加载模块(并使 Cmdlet 可用)。

    如果您不想这样做,可以使用此命令将模块导入现有的 PowerShell 会话(请注意,Azure 模块的路径可能因您安装的版本而异)。

    Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
    

    【讨论】:

    【解决方案3】:

    您使用的是哪个版本的 Azure PowerShell 模块?您是否加载了 Azure 模块,或者只是运行 PowerShell(或通过 Azure PowerShell 快捷方式)。

    这是 Azure PowerShell 模块 0.8.8.1 的输出

    PS C:\> Get-Module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   0.8.8.1    Azure                               {Add-AzureAccount, Add-AzureCacheWorkerRole, Add-AzureCert...
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
    Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    
    
    PS C:\> New-AzureStorageContext
    cmdlet New-AzureStorageContext at command pipeline position 1
    Supply values for the following parameters:
    (Type !? for Help.)
    StorageAccountName:
    

    使用 Azure PowerShell cmdlet 的最佳方式是直接从安装程序生成的快捷方式启动 Azure PowerShell。或使用Import-Module 命令导入 Azure PowerShell 模块。

    有关详细说明,请阅读How to: Install and configure Azure Power Shell module。还要检查this ServerFault question and answer

    【讨论】:

    • 我已经更新了我上面的问题,我看到的东西与你的输出有点不同,有什么想法吗?谢谢!
    【解决方案4】:

    您需要安装 azure power shell,如 microsoft site https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-1.1.0

    它就像一个魅力

    【讨论】:

    • 找不到页面。
    【解决方案5】:

    从 URL 安装 Microsoft SDK for PowerShell - https://azure.microsoft.com/en-in/downloads/

    重新启动 Windows 机器并尝试执行脚本。它会按预期工作

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多