"'New-AzureStorageContext' is not recognized," Yet the Module is Installed

14,337

Solution 1

The command New-AzureStorageContext you used belongs to the AzureRM powershell module, it is different from the new module Az , you have not installed it, that caused the issue.

To fix the issue, you could refer to the solutions below.

1.Install the AzureRM module.

2.If you want to run scripts developed for AzureRM using Az, use the Enable/Disable-AzureRmAlias cmdlets to add or remove aliases from AzureRM cmdlets to Az cmdlets.

Adds AzureRM cmdlet aliases for the given modules (or all modules if no modules are specified) to the current session (default), all sessions for the current user, or all session on the machine.

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

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

3.Use New-AzStorageContext instead of New-AzureStorageContext, it is recommended, the AzureRM module is basically deprecated, essentially they call the same api and are all for ARM, you could have a try.

For more details, see : Azure PowerShell – Cross-platform “Az” module replacing “AzureRM”.

Solution 2

New-AzureStorageContext is an old command you need if you want to continue using it with the new AZ module you have to Enable-AzureRmAlias or change command to New-AzStorageContext.

Enable-AzureRmAlias

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

Share:
14,337
user1477388
Author by

user1477388

Authored open-source project PHP One, an MVC framework for PHP designed like Microsoft's ASP.NET MVC. https://github.com/DominicArchual/Php-One

Updated on June 05, 2022

Comments

  • user1477388
    user1477388 almost 2 years

    I have installed both the Az PowerShell module and .NET Framework 4.7.2 per the instructions at https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-1.0.0 yet the client still can't find the module!

    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
    

    The error (as shown above in the output above) is:

    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.

    Am I missing something here?