Azure, powershell

Copying Azure Appsettings between App services using powershell script

In a project lifecycle you are mostly dealing with a lot of servers, each representing a stage in your project cycle.

App services usually have app settings stored in Azure which makes it quite convenient for the admin to update them from Azure and not giving access to the values to a developer.

I always felt the pain of copying down appsettings from 1 App service to another on different servers so I wrote down this simple script which does the work for me.

 

 

$myResourceGroup = ‘RG-CRM-AE-PREPROD’

 

$mySite = ‘AT-CRM-UBIQUITY-AE-PP-01’

 

$webApp = Get-AzureRmWebApp -ResourceGroupName $myResourceGroup -Name $mySite

$appSettingList = $webApp.SiteConfig.AppSettings

 

$hash = @{}

ForEach ($kvp in $appSettingList) {

$hash[$kvp.Name] = $kvp.Value

}

 

$hash[‘NewKey’] = “NewValue”

$hash[‘ExistingKey’] = “NewValue”

 

Set-AzureRmWebApp -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $hash

 

Advertisements
Standard
Azure, Uncategorized

How to deploy a Web Application to Azure using Powershell

I have been using this ps script to deploy a webapp/ webapi to Azure using Powershell. It has minimal configuration but the commands allow you to define everything from Resource Group to scaling options for that matter if there is a need.

  1. PS D:\Deploy> $WebSiteLoc=”East US”
  2. PS D:\Deploy> $WebSiteName = “PowershellTrialSaurabh”
  3. PS D:\Deploy> Test-AzureName -Website $WebSiteName
    False
  4. PS D:\Deploy> New-AzureWebsite -Location $WebSiteLoc -Name $WebSiteName

Instances : {}
NumberOfWorkers : 1
DefaultDocuments : {Default.htm, Default.html, Default.asp, index.htm…}
NetFrameworkVersion : v4.0
PhpVersion : 5.4
RequestTracingEnabled : False
HttpLoggingEnabled : False
DetailedErrorLoggingEnabled : False
PublishingUsername : $PowershellTrialSaurabh
PublishingPassword : EFWilNQrGDMoeYh1oemrku0NSn47h2P8SiPgPDaulebANQzlefzz0qFLTppQ
AppSettings : {WEBSITE_NODE_DEFAULT_VERSION}
Metadata : {}
ConnectionStrings : {}
HandlerMappings : {}
Name : PowershellTrialSaurabh
State : Running
HostNames : {powershelltrialsaurabh.azurewebsites.net}
WebSpace : saurabhfirstmvcsample-RG-EastUSwebspace
SelfLink : https://waws-prod-blu-053.api.azurewebsites.windows.net:454/subscriptions/a866dc2f-b0
ec-4247-80d2-80a365738118/webspaces/saurabhfirstmvcsample-RG-EastUSwebspace/sites/Pow
ershellTrialSaurabh
RepositorySiteName : PowershellTrialSaurabh
Sku : Free
UsageState : Normal
Enabled : True
AdminEnabled : True
EnabledHostNames : {powershelltrialsaurabh.azurewebsites.net,
powershelltrialsaurabh.scm.azurewebsites.net}
SiteProperties : Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.SitePropertie
s
AvailabilityState : Normal
HostNameSslStates : {powershelltrialsaurabh.azurewebsites.net,
powershelltrialsaurabh.scm.azurewebsites.net}
AzureDriveTraceEnabled :
AzureDriveTraceLevel : Error
AzureTableTraceEnabled :
AzureTableTraceLevel : Error
AzureBlobTraceEnabled :
AzureBlobTraceLevel : Error
ManagedPipelineMode : Integrated
WebSocketsEnabled : False
RemoteDebuggingEnabled : False
RemoteDebuggingVersion :
RoutingRules : {}
Use32BitWorkerProcess : True
AutoSwapSlotName :
SlotStickyAppSettingNames : {}
SlotStickyConnectionStringNames : {}

6. PS D:\Deploy> Show-AzureWebsite $WebSiteName
7. PS D:\Deploy> $path = “D:\Deploy\sampleazureapp.zip”
8. PS D:\Deploy> Publish-AzureWebsiteProject -Name $WebSiteName -Package $path
Change Summary:
Bytes Copied: 23380708
Files Added: 108
Files Updated: 4
Files Deleted: 1
Errors: 0
Warnings: 0
Parameters Changed: 0
Total No of Changes: 113

Standard