-
Notifications
You must be signed in to change notification settings - Fork 17
/
azure-az-sas-key.ps1
46 lines (40 loc) · 1.64 KB
/
azure-az-sas-key.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<# generate sas key #>
param(
[Parameter(Mandatory = $true)]
$resourceGroupName = '',
$storageAccountName = '.',
[ValidateSet('blob', 'file', 'table', 'queue')]
$service = @('blob', 'file', 'table', 'queue'),
[ValidateSet('service', 'container', 'object')]
$resourceType = @('service', 'container', 'object'),
$permission = 'racwdlup',
$expirationHours = 8
)
$PSModuleAutoLoadingPreference = 2
write-host "Get-AzStorageAccount -ResourceGroupName $resourceGroupName" -ForegroundColor Cyan
$accounts = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName) | where-object StorageAccountName -imatch $storageAccountName
$saskeys = [collections.arraylist]::new()
foreach ($account in $accounts) {
$blobUri = $account.Context.BlobEndPoint
write-host "creating sas for $blobUri" -ForegroundColor Green
write-host "New-AzStorageAccountSASToken -Service $($service -join ',') ``
-ResourceType $($resourceType -join ',') ``
-StartTime $((get-date).AddMinutes(-1)) ``
-ExpiryTime $((get-date).AddHours($expirationHours)) ``
-Context [$($account.context)]$($blobUri) ``
-Protocol HttpsOnly ``
-Permission $permission
" -ForegroundColor Cyan
$sas = New-AzStorageAccountSASToken -Service $service `
-ResourceType $resourceType `
-StartTime (get-date).AddMinutes(-1) `
-ExpiryTime (get-date).AddHours($expirationHours) `
-Context $account.context `
-Protocol HttpsOnly `
-Permission $permission
$sas
$saskeys.Add("$($blobUri)?$sas")
}
$global:saskeys = $saskeys
write-host "`$global:saskeys" -ForegroundColor Yellow
$saskeys