Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
param(
[string]$resourceGroup,
[string]$storageAccountName
[string]$webAppName
)
Import-Module AzureRM.Storage
$sa = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
Write-Host
Write-Host "Retrieved storage account"
Write-Verbose ($sa | Out-String)
New-AzureStorageContainer -Context $sa.Context -Name "webapp-logs" -ErrorAction Ignore | Out-Null
$sasToken = New-AzureStorageContainerSASToken -Context $sa.Context -Name webapp-logs -FullUri -Permission rwdl -ExpiryTime (Get-Date).Date.AddYears(200) -StartTime (Get-Date).Date
Write-Host
Write-Host "Generated SAS token"
Write-Verbose ($sasToken | Out-String)
$webApp = Get-AzureRmWebApp -ResourceGroupName $resourceGroup -Name $webAppName
Write-Host
Write-Host "Retrieved web app"
Write-Verbose ($webApp | Out-String)
$appSettings = [ordered]@{}
$webapp.SiteConfig.AppSettings | % { $appSettings[$_.Name] = $_.Value }
Write-Host
if ($appSettings.DIAGNOSTICS_AZUREBLOBCONTAINERSASURL -eq $null) {
$appSettings.DIAGNOSTICS_AZUREBLOBCONTAINERSASURL = [string]$sasToken
Write-Host "Updating web app"
Set-AzureRmWebApp -ResourceGroupName $resourceGroup -Name $webAppName -AppSettings $appSettings | Out-Null
} else {
Write-Host "Skipped updating web app, already contains the Diagnostics Azure Blob Container SAS URL"
}
Write-Host "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment