Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Login to Azure manually
Clear-AzureRmContext -Scope CurrentUser -Force
Login-AzureRmAccount -TenantId '<Your Azure Tenant ID>' # Microsoft
### Choose Subscription
$subscription = Get-AzureRmSubscription | Out-GridView -Title "Select the Azure subscription that you want to use ..." -PassThru
Select-AzureRmSubscription -SubscriptionId $subscription.id
# Fill in these variables
$StorageAccountName = '<YourStorageAccountName>'
$StorageContainerName = '<YourStorageContainerName>'
$StorageAccountKey = '<YourStorageAccountKey>'
$BlobName = '/SomeFolder/file.ext' # this is to construct the SAS URI below so you can test
$StgContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$StartTime = Get-Date
$EndTime = $startTime.AddHours(5.0)
# Read access - https://docs.microsoft.com/en-us/powershell/module/azure.storage/new-azurestoragecontainersastoken
$SasToken = New-AzureStorageContainerSASToken -Name $StorageContainerName `
-Context $StgContext -Permission rl -StartTime $StartTime -ExpiryTime $EndTime
$SasToken | clip
# Construnct the URL & Test
$url = "$($StgContext.BlobEndPoint)$($StorageContainerName)$($BlobName)$($SasToken)"
$url | clip
Invoke-WebRequest -UseBasicParsing -Uri $url | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment