New-AzStorageContext

In this Azure PowerShell article, We will discuss the syntax and usage of the New-AzStorageContext PowerShell command with certain examples.

New-AzStorageContext

This PowerShell command can help you quickly create an Azure Storage context.

Syntax

Below is the syntax of the New-AzStorageContext PowerShell command.

New-AzStorageContext
 [-StorageAccountName] <String>
 [-StorageAccountKey] <String>
New-AzStorageContext
 -ConnectionString <String>
New-AzStorageContext
 [-Local]
New-AzStorageContext
 [-StorageAccountName] <String>
 [-StorageAccountKey] <String>

Examples

Let’s discuss a few examples of how to use the New-AzStorageContext PowerShell command.

Example-1

You can execute the below Azure PowerShell command to create a new Azure Storage context by specifying a storage account name and Azure storage account key.

$myrg1 = "DEMORG2"
$mysactnm1 = "demoggh"
$mysactKey1 = (Get-AzStorageAccountKey -ResourceGroupName $myrg1 -AccountName $mysactnm1).Value[0]
$myctx1 = New-AzStorageContext -StorageAccountName $mysactnm1 -StorageAccountKey $mysactKey1

After executing the above PowerShell script, I got the expected output as shown below.

New-AzStorageContext

Example-2:

You can also execute the below PowerShell command to create a storage context by specifying the Azure Storage Account connection string.

New-AzStorageContext -ConnectionString "DefaultEndpointsProtocol=https;AccountName=demoggh;AccountKey=1dMSmTL3GNTqBqpi+iSbfqDY/43rqthsWb/u1EVwiKZTXsS+urwmQ+pep9tB2MeL2md8aqVZtF4C+AStq2JC8g==;EndpointSuffix=core.windows.net"

After executing the above script, I got the expected output as below

StorageAccountName  : demoggh
BlobEndPoint        : https://demoggh.blob.core.windows.net/
TableEndPoint       : https://demoggh.table.core.windows.net/
QueueEndPoint       : https://demoggh.queue.core.windows.net/
FileEndPoint        : https://demoggh.file.core.windows.net/
Context             : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                : 
StorageAccount      : DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=demoggh;AccountKey=[key hidden]
TableStorageAccount : DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=demoggh;AccountKey=[key hidden]
Track2OauthToken    : 
ShareTokenIntent    : 
EndPointSuffix      : core.windows.net/
ConnectionString    : DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=demoggh;AccountKey=1dMSmTL3GNTqBqpi+iSbfqDY/43rqthsWb/
                      u1EVwiKZTXsS+urwmQ+pep9tB2MeL2md8aqVZtF4C+AStq2JC8g==
ExtendedProperties  : {}

You can see the same output below

New-AzStorageContext PowerShell

Example-3

You can execute the below Azure PowerShell command to create a storage context with the help of the local development storage account.

New-AzStorageContext -Local

After executing the above PowerShell command, I got the below-expected output

StorageAccountName  : devstoreaccount1
BlobEndPoint        : http://127.0.0.1:10000/devstoreaccount1
TableEndPoint       : http://127.0.0.1:10002/devstoreaccount1
QueueEndPoint       : http://127.0.0.1:10001/devstoreaccount1
FileEndPoint        : 
Context             : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                : 
StorageAccount      : UseDevelopmentStorage=true
TableStorageAccount : UseDevelopmentStorage=true
Track2OauthToken    : 
ShareTokenIntent    : 
EndPointSuffix      : 
ConnectionString    : UseDevelopmentStorage=true
ExtendedProperties  : {}

You can see the same output below

New-AzStorageContext -Local

Example-4

Execute the below Azure PowerShell script to create a storage context with the help of a storage account name and key.

New-AzStorageContext -StorageAccountName "demoggh" -StorageAccountKey "1dMSmTL3GNTqBqpi+iSbfqDY/43rqthsWb/u1EVwiKZTXsS+urwmQ+pep9tB2MeL2md8aqVZtF4C+AStq2JC8g=="

After the successful execution of the above PowerShell script, I got the below-expected output.

StorageAccountName  : demoggh
BlobEndPoint        : https://demoggh.blob.core.windows.net/
TableEndPoint       : https://demoggh.table.core.windows.net/
QueueEndPoint       : https://demoggh.queue.core.windows.net/
FileEndPoint        : https://demoggh.file.core.windows.net/
Context             : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                : 
StorageAccount      : BlobEndpoint=https://demoggh.blob.core.windows.net/;QueueEndpoint=https://demoggh.queue.core.windows.net/;TableEndpoint=https://d
                      emoggh.table.core.windows.net/;FileEndpoint=https://demoggh.file.core.windows.net/;AccountName=demoggh;AccountKey=[key hidden]
TableStorageAccount : BlobEndpoint=https://demoggh.blob.core.windows.net/;QueueEndpoint=https://demoggh.queue.core.windows.net/;TableEndpoint=https://d
                      emoggh.table.core.windows.net/;FileEndpoint=https://demoggh.file.core.windows.net/;DefaultEndpointsProtocol=https;AccountName=dem
                      oggh;AccountKey=[key hidden]
Track2OauthToken    : 
ShareTokenIntent    : 
EndPointSuffix      : core.windows.net/
ConnectionString    : BlobEndpoint=https://demoggh.blob.core.windows.net/;QueueEndpoint=https://demoggh.queue.core.windows.net/;TableEndpoint=https://d
                      emoggh.table.core.windows.net/;FileEndpoint=https://demoggh.file.core.windows.net/;AccountName=demoggh;AccountKey=1dMSmTL3GNTqBqp
                      i+iSbfqDY/43rqthsWb/u1EVwiKZTXsS+urwmQ+pep9tB2MeL2md8aqVZtF4C+AStq2JC8g==
ExtendedProperties  : {}

You can see the same output below

new-azstoragecontext connection string

Wrapping Up

In this Azure PowerShell article, we discussed the syntax and usage of the New-AzStorageContext PowerShell command with certain examples. Thanks for reading this article !!!