“无法识别'New-AzureStorageContext',”模块已安装

时间:2019-01-07 18:54:25

标签: azure powershell azure-powershell

我已经按照https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-1.0.0上的说明安装了Az PowerShell模块和.NET Framework 4.7.2,但客户端仍然找不到该模块!

PS C:\Scripts> get-module Az

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.1      Az


PS C:\Scripts> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.1      Az
Script     1.0.0      Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Conn...
Script     1.0.0      Az.Aks                              {Get-AzAks, Import-AzAksCredential, New-AzAks, Remove-AzAk...
Script     1.0.0      Az.AnalysisServices                 {Add-AzAnalysisServicesAccount, Export-AzAnalysisServicesI...
Script     1.0.0      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProdu...
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, Get-AzApplicationInsightsApiKe...
Script     1.0.0      Az.Automation                       {Export-AzAutomationDscConfiguration, Export-AzAutomationD...
Script     1.0.0      Az.Batch                            {Disable-AzBatchAutoScale, Disable-AzBatchComputeNodeSched...
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzConsumpt...
Script     1.0.0      Az.Cdn                              {Confirm-AzCdnEndpointProbeURL, Disable-AzCdnCustomDomain,...
Script     1.0.0      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAc...
Script     1.0.0      Az.Compute                          {Add-AzContainerServiceAgentPoolProfile, Add-AzImageDataDi...
Script     1.0.0      Az.ContainerInstance                {Get-AzContainerGroup, Get-AzContainerInstanceLog, New-AzC...
Script     1.0.0      Az.ContainerRegistry                {Get-AzContainerRegistry, Get-AzContainerRegistryCredentia...
Script     1.0.0      Az.DataFactory                      {Get-AzDataFactory, Get-AzDataFactoryActivityWindow, Get-A...
Script     1.0.0      Az.DataLakeAnalytics                {Add-AzDataLakeAnalyticsDataSource, Add-AzDataLakeAnalytic...
Script     1.0.0      Az.DataLakeStore                    {Add-AzDataLakeStoreFirewallRule, Add-AzDataLakeStoreItemC...
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolic...
Script     1.0.0      Az.Dns                              {Add-AzDnsRecordConfig, Get-AzDnsRecordSet, Get-AzDnsZone,...
Script     1.0.0      Az.EventGrid                        {Get-AzEventGridSubscription, Get-AzEventGridTopic, Get-Az...
Script     1.0.0      Az.EventHub                         {Get-AzEventHub, Get-AzEventHubAuthorizationRule, Get-AzEv...
Script     1.0.0      Az.HDInsight                        {Add-AzHDInsightClusterIdentity, Add-AzHDInsightComponentV...
Script     1.0.0      Az.IotHub                           {Add-AzIotHubCertificate, Add-AzIotHubEventHubConsumerGrou...
Script     1.0.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertificateConta...
Script     1.0.0      Az.LogicApp                         {Get-AzIntegrationAccount, Get-AzIntegrationAccountAgreeme...
Script     1.0.0      Az.MachineLearning                  {Add-AzMlWebServiceRegionalProperty, Export-AzMlWebService...
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.0.0      Az.Media                            {Get-AzMediaService, Get-AzMediaServiceKeys, Get-AzMediaSe...
Script     1.0.0      Az.Monitor                          {Add-AzAutoscaleSetting, Add-AzLogProfile, Add-AzMetricAle...
Script     1.0.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-Az...
Script     1.0.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorization...
Script     1.0.0      Az.OperationalInsights              {Disable-AzOperationalInsightsIISLogCollection, Disable-Az...
Script     1.0.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyRemediation, Get-AzPolicyS...
Script     1.0.0      Az.PowerBIEmbedded                  {Get-AzPowerBIEmbeddedCapacity, Get-AzPowerBIWorkspace, Ge...
Script     1.0.0      Az.RecoveryServices                 {Backup-AzRecoveryServicesBackupItem, Disable-AzRecoverySe...
Script     1.0.0      Az.RedisCache                       {Export-AzRedisCache, Get-AzRedisCache, Get-AzRedisCacheFi...
Script     1.0.0      Az.Relay                            {Get-AzRelayAuthorizationRule, Get-AzRelayHybridConnection...
Script     1.0.0      Az.Resources                        {Add-AzADGroupMember, Export-AzResourceGroup, Get-AzADAppC...
Script     1.0.0      Az.ServiceBus                       {Complete-AzServiceBusMigration, Get-AzServiceBusAuthoriza...
Script     1.0.0      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceF...
Script     1.0.0      Az.SignalR                          {Get-AzSignalR, Get-AzSignalRKey, New-AzSignalR, New-AzSig...
Script     1.0.0      Az.Sql                              {Add-AzSqlDatabaseToFailoverGroup, Add-AzSqlManagedInstanc...
Script     1.0.0      Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountNe...
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsDefaultFunctionDefinition, Get-AzStr...
Script     1.0.0      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Add-AzTraffic...
Script     1.0.0      Az.Websites                         {Edit-AzWebAppBackupConfiguration, Enter-AzWebAppContainer...
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...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...


PS C:\Scripts> $context = New-AzureStorageContext -StorageAccountName "...my storage account name..." -StorageAccountKey "...my sas key..."
New-AzureStorageContext : The term 'New-AzureStorageContext' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:12
+ $context = New-AzureStorageContext -StorageAccountName "...my storage acc...
+            ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-AzureStorageContext:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

错误(如上面的输出所示)是:

  

New-AzureStorageContext:术语“ New-AzureStorageContext”不是   识别为cmdlet,函数的名称,       脚本文件或可操作程序。检查名称的拼写,或者是否包含路径,请验证路径是否为       更正并重试。

我在这里想念东西吗?

2 个答案:

答案 0 :(得分:1)

New-AzureStorageContext是旧命令,如果要继续在新的AZ模块中使用它,则必须Enable-AzureRmAlias或将命令更改为New-AzStorageContext

启用Azure天蓝色

https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-1.0.0

New-AzStorageContext

https://docs.microsoft.com/en-us/powershell/module/azure.storage/new-azurestoragecontext?view=azurermps-6.13.0

答案 1 :(得分:1)

您使用的命令New-AzureStorageContext属于AzureRM powershell模块,它与新模块Az不同,您尚未安装它,因此引起了问题。

要解决此问题,您可以参考以下解决方案。

1。安装AzureRM模块。

2。如果要使用AzureRM运行为Az开发的脚本,请使用Enable/Disable-AzureRmAlias cmdlet将别名从AzureRM cmdlet添加或删除到Az cmdlet。

将给定模块(或所有模块,如果未指定模块的话)的AzureRM cmdlet别名添加到当前会话(默认),当前用户的所有会话或计算机上的所有会话。

Enable-AzureRmAlias [-Module <string>] [-Scope Process | CurrentUser | LocalMachine]

Disable-AzureRmAlias [-Module <string[]>] [-Scope Process | CurrentUser | LocalMachine]

3。建议使用New-AzStorageContext代替New-AzureStorageContext,基本上不推荐使用AzureRM模块,从本质上讲,它们调用相同的api并且全部用于ARM,您可以使用尝试。

有关更多详细信息,请参见:Azure PowerShell – Cross-platform “Az” module replacing “AzureRM”