How do I deploy to Azure App Service with PowerShell?
You could check this blog:Deploy an App Service using Azure PowerShell to a Deployment Slot.
Get-AzurePublishSettingsFileImport-AzurePublishSettingsFile .\Your-Publish-Settings-credentials.publishsettingsGet-AzureSubscriptionSelect-AzureSubscription -SubscriptionName "The Subscription Name containing the slot"Set-AzureSubscription -SubscriptionId "ID of subscription"$WebAppName = "standard(staging)"Get-AzureWebsite -Name $WebAppNamePublish-AzureWebsiteProject -Name $WebAppName -Package "C:\PowerShell\standard.zip" -Slot "staging"
The above link (https://blogs.msdn.microsoft.com/benjaminperkins/2016/10/01/deploy-an-app-service-using-azure-powershell-to-a-deployment-slot/)talks about a GIT based deployment. OP wanted something from a folder.
Check this one out -
Unfortunately the accepted answer gave me the following error:
Get-AzureWebSite : Requested value 'PremiumV2' was not found
This StackOverflow answer suggests to use Get-AzureRmWebApp
instead, but this introduces some challenges with authentication. After some searching I found the following article which explained exactly what I needed: an approach to do a publish to Azure without any human interaction.
Please see a very simplified version of the script below.
#In the Azure portal go to (search for) "Azure Active Directory" -> #"Properties" -> Directory ID$TenantId = "<Azure Active Directory Id>"#In the Azure portal go to (search for) "Subscriptions" -> Subscription ID$SubscriptionId = "<Azure Subscription Id>"#In the Azure portal go to (search for) "Azure Active Directory" -> "App registrations" -> #Create a new registration, this will give you the ID and Secret below.#Make sure to give your new app registration sufficient rights to your app service $ServicePrincipleApplicationId = "<Service Principle Id>"$ServicePrincipleApplicationSecret = "<Service Principle Secret>"$WebAppPath = "<Local folder where your package is located>"$ResourceGroupName = "<The name of the Azure resource group that contains your app service>"$WebAppName = "<The name of your Azure app service>"$WebAppSlot = "<The name of the deployment slot you want to publish to>"$MSDeployPath = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"$source = "-source:contentPath=$WebAppPath"$publishProfileOutputPath = Join-Path -Path $ENV:Temp -ChildPath 'publishprofile.xml'$dest = "-dest:contentPath=d:\home\site\wwwroot\,publishSettings=$publishProfileOutputPath"$SecurePassword = $ServicePrincipleApplicationSecret | ConvertTo-SecureString -AsPlainText -Force$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipleApplicationId, $securePassword$connectParameters = @{ Credential = $Credential TenantId = $TenantId SubscriptionId = $SubscriptionId}Add-AzureRmAccount @connectParameters -ServicePrincipalGet-AzureRmWebAppSlotPublishingProfile -OutputFile $publishProfileOutputPath -Format WebDeploy -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlotStop-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot& $MSDeployPath @('-verb:sync', $source, $dest)Start-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot