Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/ee81125724af053ab5f6f29d24f7ba4a to your computer and use it in GitHub Desktop.
Save marckean/ee81125724af053ab5f6f29d24f7ba4a to your computer and use it in GitHub Desktop.
# 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