Edit

Share via


New-AzStorageContext

Creates an Azure Storage context.

Syntax

OAuthAccount (Default)

New-AzStorageContext
    [-StorageAccountName] <String>
    [-UseConnectedAccount]
    [-Protocol <String>]
    [-Endpoint <String>]
    [-EnableFileBackupRequestIntent]
    [<CommonParameters>]

AccountNameAndKey

New-AzStorageContext
    [-StorageAccountName] <String>
    [-StorageAccountKey] <String>
    [-Protocol <String>]
    [-Endpoint <String>]
    [<CommonParameters>]

AccountNameAndKeyEnvironment

New-AzStorageContext
    [-StorageAccountName] <String>
    [-StorageAccountKey] <String>
    -Environment <String>
    [-Protocol <String>]
    [<CommonParameters>]

AnonymousAccount

New-AzStorageContext
    [-StorageAccountName] <String>
    [-Anonymous]
    [-Protocol <String>]
    [-Endpoint <String>]
    [<CommonParameters>]

AnonymousAccountEnvironment

New-AzStorageContext
    [-StorageAccountName] <String>
    -Environment <String>
    [-Anonymous]
    [-Protocol <String>]
    [<CommonParameters>]

SasToken

New-AzStorageContext
    [-StorageAccountName] <String>
    -SasToken <String>
    [-Protocol <String>]
    [-Endpoint <String>]
    [<CommonParameters>]

SasTokenWithAzureEnvironment

New-AzStorageContext
    [-StorageAccountName] <String>
    -SasToken <String>
    -Environment <String>
    [<CommonParameters>]

OAuthAccountEnvironment

New-AzStorageContext
    [-StorageAccountName] <String>
    -Environment <String>
    [-UseConnectedAccount]
    [-Protocol <String>]
    [-EnableFileBackupRequestIntent]
    [<CommonParameters>]

AccountNameAndKeyServiceEndpoint

New-AzStorageContext
    [-StorageAccountName] <String>
    [-StorageAccountKey] <String>
    -BlobEndpoint <String>
    [-FileEndpoint <String>]
    [-QueueEndpoint <String>]
    [-TableEndpoint <String>]
    [<CommonParameters>]

OAuthAccountServiceEndpoint

New-AzStorageContext
    [[-StorageAccountName] <String>]
    [-UseConnectedAccount]
    [-BlobEndpoint <String>]
    [-FileEndpoint <String>]
    [-QueueEndpoint <String>]
    [-TableEndpoint <String>]
    [-EnableFileBackupRequestIntent]
    [<CommonParameters>]

SasTokenServiceEndpoint

New-AzStorageContext
    -SasToken <String>
    [-BlobEndpoint <String>]
    [-FileEndpoint <String>]
    [-QueueEndpoint <String>]
    [-TableEndpoint <String>]
    [<CommonParameters>]

ConnectionString

New-AzStorageContext
    -ConnectionString <String>
    [<CommonParameters>]

LocalDevelopment

New-AzStorageContext
    [-Local]
    [<CommonParameters>]

AnonymousAccountServiceEndpoint

New-AzStorageContext
    [-Anonymous]
    [-BlobEndpoint <String>]
    [-FileEndpoint <String>]
    [-QueueEndpoint <String>]
    [-TableEndpoint <String>]
    [<CommonParameters>]

Description

The New-AzStorageContext cmdlet creates an Azure Storage context. The default Authentication of a Storage Context is OAuth (Microsoft Entra ID), if only input Storage account name. See details of authentication of the Storage Service in https://learn.microsoft.com/rest/api/storageservices/authorization-for-the-azure-storage-services.

Examples

Example 1: Create a context by specifying a storage account name and key

New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >"

This command creates a context for the account named ContosoGeneral that uses the specified key.

Example 2: Create a context by specifying a connection string

New-AzStorageContext -ConnectionString "DefaultEndpointsProtocol=https;AccountName=ContosoGeneral;AccountKey=< Storage Key for ContosoGeneral ends with == >;"

This command creates a context based on the specified connection string for the account ContosoGeneral.

Example 3: Create a context for an anonymous storage account

New-AzStorageContext -StorageAccountName "ContosoGeneral" -Anonymous -Protocol "http"

This command creates a context for anonymous use for the account named ContosoGeneral. The command specifies HTTP as a connection protocol.

Example 4: Create a context by using the local development storage account

New-AzStorageContext -Local

This command creates a context by using the local development storage account. The command specifies the Local parameter.

Example 5: Get the container for the local developer storage account

New-AzStorageContext -Local | Get-AzStorageContainer

This command creates a context by using the local development storage account, and then passes the new context to the Get-AzStorageContainer cmdlet by using the pipeline operator. The command gets the Azure Storage container for the local developer storage account.

Example 6: Get multiple containers

$Context01 = New-AzStorageContext -Local
$Context02 = New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >"
($Context01, $Context02) | Get-AzStorageContainer

The first command creates a context by using the local development storage account, and then stores that context in the $Context01 variable. The second command creates a context for the account named ContosoGeneral that uses the specified key, and then stores that context in the $Context02 variable. The final command gets the containers for the contexts stored in $Context01 and $Context02 by using Get-AzStorageContainer.

Example 7: Create a context with an endpoint

New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >" -Endpoint "contosoaccount.core.windows.net"

This command creates an Azure Storage context that has the specified storage endpoint. The command creates the context for the account named ContosoGeneral that uses the specified key.

Example 8: Create a context with a specified environment

New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >" -Environment "AzureChinaCloud"

This command creates an Azure storage context that has the specified Azure environment. The command creates the context for the account named ContosoGeneral that uses the specified key.

Example 9: Create a context by using an SAS token

$SasToken = New-AzStorageContainerSASToken -Name "ContosoMain" -Permission "rad"
$Context = New-AzStorageContext -StorageAccountName "ContosoGeneral" -SasToken $SasToken
$Context | Get-AzStorageBlob -Container "ContosoMain"

The first command generates an SAS token by using the New-AzStorageContainerSASToken cmdlet for the container named ContosoMain, and then stores that token in the $SasToken variable. That token is for read, add, update, and delete permissions. The second command creates a context for the account named ContosoGeneral that uses the SAS token stored in $SasToken, and then stores that context in the $Context variable. The final command lists all the blobs associated with the container named ContosoMain by using the context stored in $Context.

Example 10: Create a context by using the OAuth Authentication

Connect-AzAccount
$Context = New-AzStorageContext -StorageAccountName "myaccountname" -UseConnectedAccount

This command creates a context by using the OAuth (Microsoft Entra ID) Authentication.

Example 11: Create a context by specifying a storage account name, storage account key and custom blob endpoint

New-AzStorageContext -StorageAccountName "myaccountname" -StorageAccountKey "< Storage Key for myaccountname ends with == >" -BlobEndpoint "https://myaccountname.blob.core.windows.net/"

This command creates a context for the account named myaccountname with a key for the account, and specified blob endpoint.

Example 12: Create a context for an anonymous storage account with specified blob endpoint

New-AzStorageContext -Anonymous -BlobEndpoint "https://myaccountname.blob.core.windows.net/"

This command creates a context for anonymous use for the account named myaccountname, with specified blob endpoint.

Example 13: Create a context by using an SAS token with specified endpoints

$SasToken = New-AzStorageContainerSASToken -Name "MyContainer" -Permission "rad"
New-AzStorageContext -SasToken $SasToken -BlobEndpoint "https://myaccountname.blob.core.windows.net/" -TableEndpoint "https://myaccountname.table.core.windows.net/" -FileEndpoint "https://myaccountname.file.core.windows.net/" -QueueEndpoint "https://myaccountname.queue.core.windows.net/"

The first command generates an SAS token by using the New-AzStorageContainerSASToken cmdlet for the container named MyContainer, and then stores that token in the $SasToken variable. The second command creates a context that uses the SAS token and a specified blob endpoint, table endpoint, file endpoint, and queue endpoint.

Example 14: Create a context by using the OAuth Authentication with a specified blob endpoint

New-AzStorageContext -UseConnectedAccount -BlobEndpoint  "https://myaccountname.blob.core.windows.net/"

This command creates a context by using the OAuth authentication with a specified blob endpoint.

Example 15: Create a context by using the OAuth Authentication on File service

New-AzStorageContext -StorageAccountName "myaccountname" -UseConnectedAccount -EnableFileBackupRequestIntent

This command creates a context to use the OAuth (Microsoft Entra ID) authentication on File service. Parameter '-EnableFileBackupRequestIntent' is required to use OAuth (Microsoft Entra ID) Authentication for File service. This will bypass any file/directory level permission checks and allow access, based on the allowed data actions, even if there are ACLs in place for those files/directories.

Parameters

-Anonymous

Indicates that this cmdlet creates an Azure Storage context for anonymous logon.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AnonymousAccount
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountEnvironment
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountServiceEndpoint
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-BlobEndpoint

Azure storage blob service endpoint

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AccountNameAndKeyServiceEndpoint
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ConnectionString

Specifies a connection string for the Azure Storage context.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ConnectionString
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-EnableFileBackupRequestIntent

Required parameter to use with OAuth (Microsoft Entra ID) Authentication for Files. This will bypass any file/directory level permission checks and allow access, based on the allowed data actions, even if there are ACLs in place for those files/directories.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OAuthAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountEnvironment
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Endpoint

Specifies the endpoint for the Azure Storage context.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OAuthAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKey
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasToken
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Environment

Specifies the Azure environment. The acceptable values for this parameter are: AzureCloud and AzureChinaCloud. For more information, type Get-Help Get-AzEnvironment.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Name, EnvironmentName

Parameter sets

AccountNameAndKeyEnvironment
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
AnonymousAccountEnvironment
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-FileEndpoint

Azure storage file service endpoint

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AccountNameAndKeyServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Local

Indicates that this cmdlet creates a context by using the local development storage account.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

LocalDevelopment
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Protocol

Transfer Protocol (https/http).

Parameter properties

Type:String
Default value:None
Accepted values:Http, Https
Supports wildcards:False
DontShow:False

Parameter sets

OAuthAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKey
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKeyEnvironment
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountEnvironment
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasToken
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountEnvironment
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-QueueEndpoint

Azure storage queue service endpoint

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AccountNameAndKeyServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SasToken

Specifies a Shared Access Signature (SAS) token for the context.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

SasToken
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenWithAzureEnvironment
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenServiceEndpoint
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-StorageAccountKey

Specifies an Azure Storage account key. This cmdlet creates a context for the key that this parameter specifies.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AccountNameAndKey
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKeyEnvironment
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKeyServiceEndpoint
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-StorageAccountName

Specifies an Azure Storage account name. This cmdlet creates a context for the account that this parameter specifies.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OAuthAccount
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKey
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKeyEnvironment
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccount
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountEnvironment
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasToken
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenWithAzureEnvironment
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountEnvironment
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AccountNameAndKeyServiceEndpoint
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TableEndpoint

Azure storage table service endpoint

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AccountNameAndKeyServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
SasTokenServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
AnonymousAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-UseConnectedAccount

Indicates that this cmdlet creates an Azure Storage context with OAuth (Microsoft Entra ID) Authentication. The cmdlet will use OAuth Authentication by default, when other authentication not specified.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OAuthAccount
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountEnvironment
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
OAuthAccountServiceEndpoint
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

Outputs

AzureStorageContext