< Back

New-AzureStorageContext

Tue Jan 29, 2019 9:27 pm

NAME New-AzureStorageContext



SYNOPSIS

Creates an Azure Storage context.





SYNTAX

New-AzureStorageContext [-StorageAccountName] <String> -Anonymous [-Endpoint <String>] [-Protocol {Http | Https}] [<CommonParameters>]



New-AzureStorageContext [-StorageAccountName] <String> -Anonymous -Environment <String> [-Protocol {Http | Https}] [<CommonParameters>]



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



New-AzureStorageContext [-StorageAccountName] <String> [-StorageAccountKey] <String> [-Endpoint <String>] [-Protocol {Http | Https}]

[<CommonParameters>]



New-AzureStorageContext [-StorageAccountName] <String> [-Endpoint <String>] [-Protocol {Http | Https}] -SasToken <String> [<CommonParameters>]



New-AzureStorageContext [-StorageAccountName] <String> [-StorageAccountKey] <String> -Environment <String> [-Protocol {Http | Https}]

[<CommonParameters>]



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



New-AzureStorageContext -Local [<CommonParameters>]





DESCRIPTION

The New-AzureStorageContext cmdlet creates an Azure Storage context.





PARAMETERS

-Anonymous [<SwitchParameter>]

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



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-ConnectionString <String>

Specifies a connection string for the Azure Storage context.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Endpoint <String>

Specifies the endpoint for the Azure Storage context.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Environment <String>

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

`Get-Help Get-AzureEnvironment`.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Local [<SwitchParameter>]

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



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Protocol <String>

Transfer Protocol (https/http).



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-SasToken <String>

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



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-StorageAccountKey <String>

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



Required? true

Position? 1

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-StorageAccountName <String>

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



Required? true

Position? 0

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

None

This cmdlet does not accept any input.





OUTPUTS

AzureStorageContext







NOTES









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



C:\\PS>New-AzureStorageContext -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



C:\\PS>New-AzureStorageContext -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



C:\\PS>New-AzureStorageContext -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



C:\\PS>New-AzureStorageContext -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



C:\\PS>New-AzureStorageContext -Local | Get-AzureStorageContainer



This command creates a context by using the local development storage account, and then passes the new context to the Get-AzureStorageContainer

cmdlet by using the pipeline operator. The command gets the Azure Storage container for the local developer storage account.





Example 6: Get multiple containers



C:\\PS>$Context01 = New-AzureStorageContext -Local

PS C:\\> $Context02 = New-AzureStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with

== >"

PS C:\\> ($Context01, $Context02) | Get-AzureStorageContainer



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-AzureStorageContainer .





Example 7: Create a context with an endpoint



C:\\PS>New-AzureStorageContext -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



C:\\PS>New-AzureStorageContext -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



C:\\PS>$SasToken = New-AzureStorageContainerSASToken -Name "ContosoMain" -Permission "rad"

PS C:\\> $Context = New-AzureStorageContext -StorageAccountName "ContosoGeneral" -SasToken $SasToken

PS C:\\> $Context | Get-AzureStorageBlob -Container "ContosoMain"



The first command generates an SAS token by using the New-AzureStorageContainerSASToken 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.







RELATED LINKS

Online Version: https://docs.microsoft.com/en-us/powers ... agecontext

Get-AzureStorageBlob

New-AzureStorageContainerSASToken