I am using VSTS Release Management. In my release flow I add a task 'Azure PowerShell(Run a PowerShell script within an Azure environment)' to run a simple script to set some key vaues in the web.config of a web app:
Set-AzureWebsite -Name $AzureWebsiteName -AppSettings $appsettings
When I run the deployment, I get the following error (related to the script):
[error]No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
The task is configured to use the connection type "Azure Resource Manager" and so far I understood that 'Set-AzureWebsite' should be used in classic mode?
Is there another way to set the AppSettings with the Azure Ressource Manager Mode=
The name Azure websites changes to Azure App Service Web Apps in the ARM, so you can use: Set-AzureRmWebApp
Replace below command:
Set-AzureWebsite $webAppName -AppSettings $appSettingsHash
With this command:
Set-AzureRmWebApp -AppSettings $appSettingsHash -Name $webAppName -ResourceGroupName $resourceGroupName
Related
I need specify one app setting as "deployment slot setting" so as to assign different value in Prod and Staging slots and keep the value stick to slot when swapping the slots. I know I can do it on azure portal as below screen shot. But how to do it using powershell?
I tried the powrshell cmd Set-AzWebAppSlot:
Set-AzWebAppSlot -AppSettings $newAppSettings -Name $webAppName -ResourceGroupName $resourceGroupName -Slot "Staging"
But the settings set with above command are not marked as "Deployment slot setting"
If you want to configure an app setting or connection string to stick to a specific slot (not swapped),
use Set-AzWebAppSlotConfigName:
Set-AzWebAppSlotConfigName -ResourceGroupName <group-name> -Name <app-name> -AppSettingNames <setting-name1>,<setting-name2>,...
Reference link: https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=ps#configure-app-settings
I am trying to create an API App in Azure App Service with PowerShell.
The cmdlet I am calling always create a Web App by default. If it is possible, I would like to know how I can specify the type/kind to be Api App instead of Web App?
New-AzureRmWebApp -Name $name -Location $location -AppServicePlan $plan -ResourceGroupName $resourceGroup
From my reading there is not much different between both except the icon, is it worth it to set the type to "Api App" if it's what my app is all about?
I am using version 5.4.0 of AzureRM PowerShell module.
> Get-Module "AzureRM"
ModuleType Version Name
---------- ------- ----
Script 5.4.0 AzureRM
Just call New-AzureRmResource instead and pass in -Kind 'api':
# CREATE "just-an-api" API App
$ResourceLocation = "West US"
$ResourceName = "just-an-api"
$ResourceGroupName = "demo"
$PropertiesObject = #{
# serverFarmId points to the App Service Plan resource id
serverFarmId = "/subscriptions/SUBSCRIPTION-GUID/resourceGroups/demo/providers/Microsoft.Web/serverfarms/plan1"
}
New-AzureRmResource -Location $ResourceLocation `
-PropertyObject $PropertiesObject `
-ResourceGroupName $ResourceGroupName `
-ResourceType Microsoft.Web/sites `
-ResourceName "just-an-api/$ResourceName" `
-Kind 'api' `
-ApiVersion 2016-08-01 -Force
..which produces an API App, a Microsoft.Web/sites resource type of the api kind:
Hold on.. How did you come up with this stuff?
Visit https://resources.azure.com and navigate to an existing API App, build the PowerShell syntax by combining the PowerShell tab with the desired values from the JSON resource definition.
There is not a parameter in New-AzureRmWebApp supported to explicitly indicate whether API App or Web App. The resource provider is still Microsoft.Web. And there is no parameter which indicates the type in ARM template.
These two types technically still work in the same way. The difference would be the purpose, icon, OS running choice and debugging capability (refer here What is the difference between an API App and a Web App?).
You may want to classify between the two types by tagging it, which would help manage in case your resource groups have many web resources.
You can create API App via Azure Portal, or Visual Studio.
Also, look at Azure API Management for more flexibility of API wrapping instead of Azure App Service.
I am trying to add new ip addresses to the whitelist of Azure AppService. I am unable to use XML Transformation or simply replace tokens as the needed list of new entries will be obtained in the beginning of the release and not before. I am also unable to modify the content of the zipped site (published with /p:DeployOnBuild=True). The deployment is done using "Azure App Service Deploy" task. I know of Set-AzureRMWebApp cmdlet but it only allows to modify the appSettings and connectionStrings sections. It there any other solution?
Using Set-AzureRMResource PowerShell command:
$r = Get-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01
$p = $r.Properties
$p.ipSecurityRestrictions = #()
$restriction = #{}
$restriction.Add("ipAddress","0.0.0.0")
$restriction.Add("subnetMask","0.0.0.0")
$p.ipSecurityRestrictions+= $restriction
Set-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01 -PropertyObject $p
A Related thread: Azure Resource Manager IP Security Restrictions using Powershell
Another way is that you can publish project with FileSystem method:
Some Build Tasks:
Visual Studio Build (MSBuild Arguments: /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish)
Publish Build Artifacts (Path to Publish: $(build.artifactstagingdirectory))
Release Tasks:
Replace token or Other tasks to update web.config (Could use File Transform & Variable Substitution in Azure App Service Deploy task)
Azure App Service Deploy (1. Uncheck Publish using WebDeloy option 2. Package or folder: $(System.DefaultWorkingDirectory)
I'm trying to run some azure powershell commands as part of my Visual Studio Team Services build using Azure Resource Manager.
It gives me the following error:
No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
The commands I'm trying to run:
$website = Get-AzureWebsite | where {$_.Name -eq 'my-website'}
Write-Output ("##vso[task.setvariable variable=DeployUrl;]$website.HostNames")
When I tried to run it locally, I had to call
Add-AzureAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"
to get it working, but it is not possible in the VSTS build.
UPDATE:
I've configured it to use the azure classic mode instead of resource manager, at it works. I don't think that it is a feasible solution for production as azure classic mode is obsolete.
Since you are using Azure Resource Manager, please check the things below:
Make sure "Azure Resource Manager" service endpoint is added correctly.
Use "Get-AzureRmWebApp" command instead of "Get-AzureWebsite" command just as bmoore mentioned.
I have tested it at my side, it works correctly.
My PowerShell script:
$website = Get-AzureRmWebApp | where {$_.Name -eq 'eddieapp0930'}
Write-Host $website.HostNames
Run from "Azure PowerShell Script" task:
Thank you for your question.
If you are using service manager mode(classic mode), the correct cmdlet is:
Add-AzureAccount
Get-AzureSubscription -SubscriptionName “name” | Select-AzureSubscription
If you are using Resource Manager, the correct cmdlet is:
Login-AzureRmAccount
Get-AzureRmSubscription –SubscriptionName "name" | Select-AzureRmSubscription
or just use -SubscriptionId instead of -SubscriptionName.
More information about ASM and ARM, please refer to the link below:
https://azure.microsoft.com/en-us/documentation/articles/resource-manager-deployment-model/
If you still have questions, welcome to post back here. Thanks.
I want to stop and de-allocate a Windows VM in Azure.
In PowerShell, I use the command:
Stop-AzureVM - ServiceName [servicename] - Name [machinename] - Force
However, I get the following error message in PowerShell:
WARNING: "No deployment found in service [servicename]
What could be wrong?
Troubleshooting steps:
Is the VM already in Shutdown or Deallocated state.
Do you have more than one subscriptions. If yes then select correct subscription using below cmdlet and then try to stop the VM:
Select-AzureSubscription -SubscriptionName "<<Your SubscriptionName here>>"
or
Select-AzureSubscription -Id "<<Your Subscription ID>>"
If you have only one Azure Subscription then check if you created the VM using ASM i.e. old portal (https://manage.windowsazure.com) or ARM i.e. new portal (https://portal.azure.com). If you used new portal then you need to use ARM related PowerShell cmdlets like below:
Stop-AzureRmVM -ResourceGroupName "resource group name" -Name "VM name"
Reference for ARM PowerShell cmdlets: Azure Resource Manager and PowerShell