Powershell script to get all app services linked with there certificates - azure

Can somebody tell me how can I build a script that can list out all the app service certificates inside of an app services and app service plan that the app services are linked with inside of any azure subscription?

Based on the official documentation, Azure PowerShell does not support get certificate and service plan via the App Service Name . If you want to do it, you could get them via resource group.
1.Get Web App certificates in a resource group
Get-AzureRmWebAppCertificate -ResourceGroupName <resourcegroup>
2.Get App Service plans from a resource group
Get-AzureRmAppServicePlan -ResourceGroupName <resourcegroup>
For more details, refer to Get-AzureRmWebAppCertificate & Get-AzureRmAppServicePlan.

Related

Error when trying to create a webapp using CLI

I have no experience in coding, just started now.
I am trying to create a webapp using the Azure Cloud Shell, so I used the following command:
az webapp create --name WebAppOne --resource-group learn-64c4ca17-0293-40f6-ba23-e4581751cca0 --plan ServicePlanTest
Then I get the message:
Webapp 'WebAppOne' already exists. The command will use the existing app's settings.
Unable to retrieve details of the existing app 'WebAppOne'. Please check that the app is a part of the current subscription
I only have one subscription in Azure as I am still using a free account for learning purposes.
So, I decided to get a list showing the webapps that exist by using the command:
az webapp list --output table
However, the only outcome is a blank line, showing no web apps already existing. What should I try next?
To create a web app in Azure App service, you must have a resource group and App service plan in your subscription.
To check the existing App services in your subscription
az webapp list --resource-group MyRGName
Output :
As you can see, currently I don't have any webapps created in the given Resource group
Run the below command to create an Azure Web App
az webapp create --name MyWebApp --resource-group MyRGName --plan MyAppServicePlan
Though I don't have any Webapps with the given name, I got the same error.
In Azure Portal => Azure Active Directory => App registrations => All applications
In search box, searched with the web app name. I can see the web app with same name is already created.
Reason for the error
You might have created a web app with same name long ago, but the resource got deleted from the resource group. But still, it is available in the Azure Active Directory App registrations.
If it is created by you and you don't want to use anymore, you can delete it. If not create web app with another name.
Tried to create web app with another name.
Create Azure App Service:
Now I can see the created Web App List.
List of Azure Web Apps

Does the App Service Plans in Azure get moved when i move resources in a Resource Group?

I am trying to move resources from a resource group in one subscription to another in Azure.
Im using Powershell as follows:
Validate
Invoke-AzResourceAction -Action validateMoveResources `
-ResourceId "/subscriptions/{subscription-id}/resourceGroups/{source-rg}" `
-Parameters #{ resources= #("/subscriptions/{subscription-id}/resourceGroups/{source-
rg}/providers/{resource-provider}/{resource-type}/{resource-name}",
"/subscriptions/{subscription-id}/resourceGroups/{source-rg}/providers/{resource-
provider}/{resource-type}/{resource-name}", "/subscriptions/{subscription-
id}/resourceGroups/{source-rg}/providers/{resource-provider}/{resource-type}/{resource-
name}");targetResourceGroup = '/subscriptions/{subscription-
id}/resourceGroups/{destination-rg}' }
Move
$webapp = Get-AzResource -ResourceGroupName OldRG -ResourceName ExampleSite
$plan = Get-AzResource -ResourceGroupName OldRG -ResourceName ExamplePlan
Move-AzResource -DestinationResourceGroupName NewRG -ResourceId $webapp.ResourceId,
$plan.ResourceId
The App service that I have connects to a database so Im assuming that the database needs to be in that same RG for it to be moved ?
Also each resource for example the App Service sits under an App Service Plan, does the App Service Plan get created and moved over into the new Subscripton ?
Are database firewall rules moved across as well ?
If you move the resources across the Subscriptions/ Resource group, you have to move the entire resources which you want to move.
If your move requires setting up new dependent resources, you'll experience an interruption in those services until they've been re-configured.
The App service that I have connects to a database so I'm assuming that the database needs to be in that same RG for it to be moved?
Yes, it should be in the same resource group. or you have to re-configure the database connections according to yours.
Also, each resource for example the App Service sits under an App Service Plan, does the App Service Plan get created and moved over into the new Subscription?
Yes, App Service plan can be move to new subscription. But we have some limitations to move App Service from one Resource Group/Subscription to another.
Moving a resource to a new resource group or subscription is merely a metadata modification that should have no impact on how the resource works. The inbound IP address for an app service, for example, does not change when the app service is moved.
There must be no existing App Service resources in the target resource group. Among the App Service's resources are:
Web Apps
App Service plans Uploaded or imported
TLS/SSL certificates
App Service Environments
All App Service resources in the resource group must be moved together.
References
Move resources to a new resource group / subscription
App Service Limitations

is it possible to list all types of app service using az cli

I am trying to list the type of app service associated with particular subscription using azure cli.
Type of app service:
Web apps
logic apps
Function apps
mobile apps
API apps
So far I have tried to find out the individual command for these. Out of which I could only get
web apps : az webapp list --subscription subscriptionId
function apps: az functionapp list --subscription subscriptionId
logic apps: az logic workflow list --subscription subscriptionId
I am not sure the above commands include the API apps and mobile apps or it filters.
Any help would be much appreciated.
You could use az resource list (see documentation) and apply a query filter
az resource list --subscription subscriptionId --query "[?type=='Microsoft.Web/sites' || type=='Microsoft.Logic/workflows']"
You could update the query filter based on your need.
As mentioned by #Sajeetharan, Mobile Apps, API Apps, Web Apps and Function Apps are part of App services (Microsoft.Web/sites)
Yes you are right, API apps and Mobile apps are part of the Appservice which falls under WebApps.
You could use the CLI command or use the REST API

how to fix 'conflicts with an already existing hostname' while cloning web app using Azure cloudshell

Scenario: You want to clone an app to another region, while configuring an Azure Resource Manager traffic manager profile that includes both apps.
Below are the commands I tried
$srcapp = Get-AzWebApp -ResourceGroupName SourceAzureResourceGroup -Name
source-webapp
$destapp = New-AzWebApp -ResourceGroupName DestinationAzureResourceGroup -Name dest-webapp -Location "South Central US" -AppServicePlan DestinationAppServicePlan -SourceWebApp $srcapp -TrafficManagerProfileName newTrafficManagerProfile
the above commands fail with ""Creating app with backup from 'subscriptiondetailshere' failed: Detail: Hostname \'abc.xyz.companydomain.com\' conflicts with an already existing hostname. ExtendedCode: 04005"
FYI : the apps are hosted in standard app service plan. I did read documentation saying only the premium apps can be cloned but I was able to clone this particular app in standard plan through Azure Portal UI.
I want to be able to automate this using the ps. Any pointers are appreciated
https://learn.microsoft.com/en-us/azure/app-service/app-service-web-app-cloning
Update:
copied web app:
Traffic manager:
First, azure web app clone does support standard app service plan. Here is a screenshot from the doc:
Second, the code you're using is correct, I did a test at my side, it's working fine(The web app is copied from central us to west us, after copied, everything is working fine):
For the conflicting error, you should check in your destination resource group if there is a existing web app with that host name(you mentioned that you can copy from azure portal, maybe you didn't delete it when you were using code to copy it).

Change App Service Plan does not working after move to another resource Group

I have a strange issue in azure portal after moving my WebApp and App Service Plan to another resource group. After click to Change App Service Plan I'm getting that info:
Application is worrking but I can't do anything with App Service Plan settings, moreover I can't event do this from powershell with using command:
Set-AzureRmWebApp -Name <webapp name> -ResourceGroupName <resource group name> -AppServicePlan <new app service plan>
Ticket submitted for support!
Does anyone know how to fix it?
#komluk, As Avanish said that you can't move WebApp resources between web spaces and Moving web apps to App Service plans that are in data centers in different geographical locations is not supported.

Resources