无法识别"New-AzureStorageContext"

Mis*_*pic 7 powershell azure

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

Set-Variable -Name StorageContext -Value (New-AzureStorageContext -ConnectionString $storageConnectionString)
Run Code Online (Sandbox Code Playgroud)

我的错误是:

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安装了Azure PowerShell和Microsoft Azure SDK以及Microsoft 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...}    
Run Code Online (Sandbox Code Playgroud)

Sim*_*n W 7

您尚未加载Azure PowerShell模块(因此您从列表中删除它).当您安装Cmdlet时,您还将获得一个新的快捷方式"Microsoft Azure Powershell",它将自动为您加载模块(并使Cmdlet可用).

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

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
Run Code Online (Sandbox Code Playgroud)

  • 或者运行“Import-Module -Name Az”,如下所述:https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-4.6.1#sign-in (2认同)

小智 6

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

  • 正如您所建议的,对于 PowerShell Core Az-library,命令是“New-AzStorageContext”。因此,会出现混乱,因为“New-AzureStorageContext”适用于某些用户,但不适用于某些用户。 (3认同)