【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken

简介: 【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken

问题描述

使用PowerShell脚本如何来创建存储账号(Storage Account)的共享访问签名呢?查询到可以使用 New-AzStorageContainerSASToken 命令来生成Azure Storage container的SAS Token。

The New-AzStorageContainerSASToken cmdlet generates a Shared Access Signature (SAS) token for an Azure storage container.

 

New-AzStorageContainerSASToken [-Name] <String> -Policy <String>

[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>] [-ExpiryTime <DateTime>]

[-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]

 

Source:https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontainersastoken?view=azps-8.0.0

是否有一个可以参考的例子呢?

 

示例代码

#Now we need to create Storage context
$context = New-AzStorageContext -StorageAccountName yourstorageaccountname -StorageAccountKey yourstorageaccountkey
$StartTime = Get-Date
$EndTime = $startTime.AddDays(1)
$policy=New-AzStorageContainerStoredAccessPolicy -Container "yourcontainername" -Policy "yourstoredaccesspolicy" -Permission rwd  -StartTime $StartTime -ExpiryTime $EndTime -Context $context -Debug
New-AzStorageContainerSASToken -Name "yourcontainername" -Policy $policy  -Protocol HttpsOrHttp  -Context $context

第一步:通过 New-AzStorageContext 创建content对象

第二步:通过 New-AzStorageContainerStoredAccessPolicy 创建SAS的访问策略

第三步:调用 New-AzStorageContainerSASToken 生成目前存储账号的SAS Token

 

参考资料

创建Storage Context:https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontext?view=azps-6.3.0

创建存储访问策略请参考:https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontainerstoredaccesspolicy?view=azps-6.3.0

创建SAS Token:https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontainersastoken?view=azps-6.3.0

Power shell安装介绍:https://docs.azure.cn/zh-cn/storage/blobs/storage-quickstart-blobs-powershell

 

相关文章
|
20天前
【Azure 应用服务】Azure Powershell Function 出错 The term 'Connect-AzAccount' is not recognized
【Azure 应用服务】Azure Powershell Function 出错 The term 'Connect-AzAccount' is not recognized
|
20天前
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
|
20天前
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
|
20天前
|
存储 C# Python
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
|
20天前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
20天前
|
数据安全/隐私保护 异构计算 Windows
【Azure 环境】 介绍两种常规的方法来监视Window系统的CPU高时的进程信息: Performance Monitor 和 Powershell Get-Counter
【Azure 环境】 介绍两种常规的方法来监视Window系统的CPU高时的进程信息: Performance Monitor 和 Powershell Get-Counter
|
10月前
|
Shell Linux 开发工具
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
77 0
|
JavaScript Windows
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
|
Windows
使用PowerShell获取Windows当前锁屏壁纸
使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
159 0
|
应用服务中间件 nginx Windows
Windows PowerShell 中启动 Nginx 报错解决方案
Windows PowerShell 中启动 Nginx 报错解决方案
Windows PowerShell 中启动 Nginx 报错解决方案