Edit

Share via


Set-AzStorageCORSRule

Sets the CORS rules for a type of Storage service.

Syntax

Default (Default)

Set-AzStorageCORSRule
    [-ServiceType] <StorageServiceType>
    -CorsRules <PSCorsRule[]>
    [-PassThru]
    [-Context <IStorageContext>]
    [-ServerTimeoutPerRequest <Int32>]
    [-ClientTimeoutPerRequest <Int32>]
    [-DefaultProfile <IAzureContextContainer>]
    [-ConcurrentTaskCount <Int32>]
    [<CommonParameters>]

Description

The Set-AzStorageCORSRule cmdlet sets the Cross-Origin Resource Sharing (CORS) rules for a type of Azure Storage service. The types of storage services for this cmdlet are Blob, Table, Queue, and File. This cmdlet overwrites the existing rules. To see the current rules, use the Get-AzStorageCORSRule cmdlet.

Examples

Example 1: Assign CORS rules to the blob service

$CorsRules = (@{
    AllowedHeaders=@("x-ms-blob-content-type","x-ms-blob-content-disposition");
    AllowedOrigins=@("*");
    MaxAgeInSeconds=30;
    AllowedMethods=@("Get","Connect")},
    @{
    AllowedOrigins=@("http://www.fabrikam.com","http://www.contoso.com");
    ExposedHeaders=@("x-ms-meta-data*","x-ms-meta-customheader");
    AllowedHeaders=@("x-ms-meta-target*","x-ms-meta-customheader");
    MaxAgeInSeconds=30;
    AllowedMethods=@("Put")})

Set-AzStorageCORSRule -ServiceType Blob -CorsRules $CorsRules

The first command assigns an array of rules to the $CorsRules variable. This command uses standard extends over several lines in this code block. The second command assigns the rules in $CorsRules to the Blob service type.

Example 2: Change properties of a CORS rule for blob service

$CorsRules = Get-AzStorageCORSRule -ServiceType Blob
$CorsRules[0].AllowedHeaders = @("x-ms-blob-content-type", "x-ms-blob-content-disposition")
$CorsRules[0].AllowedMethods = @("Get", "Connect", "Merge")
Set-AzStorageCORSRule -ServiceType Blob -CorsRules $CorsRules

The first command gets the current CORS rules for the Blob type by using the Get-AzStorageCORSRule cmdlet. The command stores the rules in the $CorsRules array variable. The second and third commands modify the first rule in $CorsRules. The final command assigns the rules in $CorsRules to the Blob service type. The revised rules overwrite the current CORS rules.

Parameters

-ClientTimeoutPerRequest

Specifies the client-side time-out interval, in seconds, for one service request. If the previous call fails in the specified interval, this cmdlet retries the request. If this cmdlet does not receive a successful response before the interval elapses, this cmdlet returns an error.

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:ClientTimeoutPerRequestInSeconds

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ConcurrentTaskCount

Specifies the maximum concurrent network calls. You can use this parameter to limit the concurrency to throttle local CPU and bandwidth usage by specifying the maximum number of concurrent network calls. The specified value is an absolute count and is not multiplied by the core count. This parameter can help reduce network connection problems in low bandwidth environments, such as 100 kilobits per second. The default value is 10.

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Context

Specifies an Azure Storage context. To obtain a context, use the New-AzStorageContext cmdlet.

Parameter properties

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

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-CorsRules

Specifies an array of CORS rules. You can retrieve the existing rules using the Get-AzStorageCORSRule cmdlet.

Parameter properties

Type:

PSCorsRule[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-PassThru

Indicates that this cmdlet returns a Boolean that reflects the success of the operation. By default, this cmdlet does not return a value.

Parameter properties

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

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ServerTimeoutPerRequest

Specifies the length of the time-out period for the server part of a request.

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:ServerTimeoutPerRequestInSeconds

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ServiceType

Specifies the Azure Storage service type for which this cmdlet assigns rules. The acceptable values for this parameter are:

  • Blob
  • Table
  • Queue
  • File

Parameter properties

Type:StorageServiceType
Default value:None
Accepted values:Blob, Table, Queue, File
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
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

IStorageContext

Outputs

PSCorsRule