Azure clone app via Powershell - InternalServerError - azure

I've been following this guide to cloning an existing app. I'm running the Az Powershell Module via Docker.
Here's what I ran:
$destapp = New-AzWebApp -ResourceGroupName HLP-API-NEW -Name hlp-api-new -Location "UK South" -AppServicePlan hlp-api-plan-new -SourceWebApp $srcapp
HLP-API-NEW is a new resource group that I created; hlp-api-plan-new is likewise a new service plan.
Here's how I got $srcapp:
$srcapp = Get-AzWebApp -ResourceGroupName HLP-API -Name api-hlp
The service plan / resource group nams are definitely correct. I get the following error:
New-AzWebApp: Long running operation failed with stauts 'InternalServerError'
Does anyone know why this might be?

Please make sure your app is not under the below conditions. if it is in the below condition, we can't be able to clone it.
Restrictions to clone app
Auto scale settings are not cloned
Backup schedule settings are not cloned
VNET settings are not cloned
App Insights are not automatically set up on the destination app
Easy Auth settings are not cloned
Kudu Extension are not cloned
TiP rules are not cloned
Database content is not cloned
Outbound IP Addresses changes if cloning to a different scale unit
Not available for Linux Apps
Managed Identities are not cloned
Not available for Function Apps
If your app is not in the above criteria, you can clone it.
Ways follows
1. Using Slot parameter
To clone an existing app including all associated deployment slots, you need to use the Slots parameter.
$srcappslot = Get-AzWebAppSlot -ResourceGroupName <Your Resource Group> -Name <Your app name> -Slot <slot name>
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your new app name> -Location <location to create app> -AppServicePlan <App service plan name> -SourceWebApp $srcappslot
2. Using the new App Service plan
$srcapp = Get-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your app name>
New-AzAppServicePlan -Location "Central US" -ResourceGroupName <Your Resource Group> -Name <App Service plan Name> -Tier Standard
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <new app name to create> -Location <Location to create app> -AppServicePlan <Your new app service name> -SourceWebApp $srcapp
3. Using Existing App Service plan
$srcapp = Get-AzWebApp -ResourceGroupName <Your Resource Group> -Name <Your app name>
$destapp = New-AzWebApp -ResourceGroupName <Your Resource Group> -Name <new app name to create> -Location <Location to create app> -AppServicePlan <Specify exact App service file path (APP SERVICE PLAN> PROPERTIES>RESOURCEID)> -SourceWebApp $srcapp

I have the same problem, I don't understand what's wrong with my command. While scouring the Internet I found this command which is leading me towards a solution. You may find it helpful as well:
PS> Resolve-AzError
This provided me the clue I needed to chase:
Message : Long running operation failed with status 'InternalServerError'.
ServerMessage : Restore failed with errors: Detail: Hostname 'abc.somedomain.com' conflicts with an already existing hostname.
ExtendedCode: 04005
Good luck!

Related

How do you associate an Azure web app with a vnet using PowerShell Az?

I know it can be done using Azure CLI like this:
az webapp vnet-integration add -g $resourceGroupName -n $applicationName --vnet $vnetName --subnet $subnetName
Is there an equivalent command using PowerShell Az?
If you reference the docs at https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet, at the bottom is a link to the Script Center gallery where this is a full PS1 script at https://gallery.technet.microsoft.com/scriptcenter/Connect-an-app-in-Azure-ab7527e3 which shows how to integrate web app with vnet.
The final lines of interest (it uses AzureRM, but should be easy to convert to Az):
$PropertiesObject = #{
"vnetName" = $VirtualNetworkName; "vpnPackageUri" = $packageUri
}
New-AzureRmResource -Location $location -Properties $PropertiesObject -ResourceName "$($webAppName)/$($vnetName)/primary" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections/gateways" -ApiVersion 2015-08-01 -ResourceGroupName $webAppResourceGroup -Force

How to create a Linux AppService Plan with New-AzAppServicePlan?

What is the equivalient of this code using New-AzAppServicePlan?
az appservice plan create --resource-group $ServerFarmResourceGroupName `
--name $AppServicePlanName `
--is-linux `
--location $ResourceGroupLocation `
--sku $AppServicePlanTier `
--number-of-workers $NumberOfWorkers
Is there really no way to create an App Service Plan using Az Powershell? Why can it only be done via Azure CLI or ARM?
I only found this answer, which basically uses ARM directly: How do I use Powershell to create an Azure Web App that runs on Linux?
There are some issues about this, suppose for now this is not supported for New-AzureRmAppServicePlan, however you could use New-AzureRmResource to create a linux plan. You could try the below command.
New-AzureRmResource -ResourceGroupName <>group name -Location "Central US" -ResourceType microsoft.web/serverfarms -ResourceName <plan name> -kind linux -Properties #{reserved="true"} -Sku #{name="S1";tier="Standard"; size="S1"; family="S"; capacity="1"} -Force
I originally used my script to create a ConsumptionPlan (Y1) through PowerShell and AzureCLI because I don't like when Azure put a generated name when creating a ConsumptionPlan.
Please find my solution to create a Linux App Service Plan (B1) using New-AzResource:
$fullObject = #{
location = "West Europe"
sku = #{
name = "B1"
tier = "Basic"
}
kind = "linux"
properties = #{
reserved = $true
}
}
$resourceGroupName = "rg-AppServicePlanLinux"
$serverFarmName = "aspl-test"
Write-Host "Step 1: CREATING APP SERVICE PLAN B1:Basic named [$serverFarmName]"
# Create a server farm which will host the function app in the resource group specified
New-AzResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Web/serverfarms" -Name $serverFarmName -IsFullObject -PropertyObject $fullObject -Force
So I used the ARM template to understand which information you need to provide on the -PropertyObject parameter
It also now seems possible to do an App Service Plan Linux with New-AzAppServicePlan command since Az PowerShell 4.3.0 (June 2020) with the parameter -Linux
Az.Websites
Added safeguard to delete created webapp if restore failed in 'Restore-AzDeletedWebApp'
Added 'SourceWebApp.Location' for 'New-AzWebApp' and 'New-AzWebAppSlot'
Fixed bug that prevented changing Container settings in 'Set-AzWebApp' and 'Set-AzWebAppSlot'
Fixed bug to get SiteConfig when -Name is not given for Get-AzWebApp
Added a support to create ASP for Linux Apps
Added exceptions for clone across resource groups
Release Note: https://learn.microsoft.com/en-us/powershell/azure/release-notes-azureps?view=azps-5.6.0&viewFallbackFrom=azps-4.3.0#azwebsites-7
New-AzAppServicePlan: https://learn.microsoft.com/en-us/powershell/module/az.websites/new-azappserviceplan?view=azps-5.6.0
If you get "The Service is unavailable" after deploying your new Function app (Consumption Plan) with Azure CLI, please make sure the following statement from Microsoft:
https://github.com/Azure/Azure-Functions/wiki/Creating-Function-Apps-in-an-existing-Resource-Group
I waste the whole day because I got another Function App (Premium Plan) in the same resource group I used to deploy the Consumption one.
This worked for me:
Adding -Linux as a parameter to my command
New-AzAppServicePlan -ResourceGroupName $RESOURCE_GROUP_NAME -Name $APP_SERVICE_PLAN_NAME -Location $RESOURCE_LOCATION -Linux -Tier $APP_SERVICE_PLAN_TIER -NumberofWorkers $APP_SERVICE_PLAN_WORKERS -WorkerSize $APP_SERVICE_PLAN_WORKER_SIZE
Example:
New-AzAppServicePlan -ResourceGroupName 'MyResourceGroup' -Name 'MyServicePlan' -Location 'northeurope' -Linux -Tier 'PremiumV2' -NumberofWorkers 2 -WorkerSize Medium
That's all.
I hope this helps

how to read service configuration (.cscfg) of a cloud service created on RM subscription

I have a cloud service (classic) created on RM subscription. I need to read its service config (.cscfg), update the config and redrploy it back to the cloud service.
I did it using get-azuredeploy command on Classic, but this command doesnt work on RM subscription.
does anyone know how to get service config from RM subscription?
Try the command below, the $slot.Properties.configuration should be that.
$slot = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.ClassicCompute/domainNames/slots -ResourceName "xxxxx" -ApiVersion 2016-04-01
$slot.Properties.configuration

How do I create an Image of a VM using Azure Resource Manager

I've been using the classic Azure Portal for a while now, and I know how to create a VM, customize it, then capture it as an Image and use that image to create more VMs.
Now I'm trying to use the new Azure Portal. I created the VM and customized it, now I want to capture an image so I can make more VMs exactly the same way. The problem is the new web portal doesn't capture option.
As far as I know, you can do it via Powershell:
Login-AzureRmAccount
Get-AzureRmSubscription
Select-AzureRmSubscription -SubscriptionId "<subscriptionID>"
Stop-AzureRmVM -ResourceGroupName <resourceGroup> -Name <vmName>
Set-AzureRmVm -ResourceGroupName <resourceGroup> -Name <vmName> -Generalized
Save-AzureRmVMImage -ResourceGroupName <resourceGroupName> -Name <vmName> `
-DestinationContainerName <destinationContainerName> -VHDNamePrefix <templateNamePrefix> `
-Path <C:\local\Filepath\Filename.json>
For more details visit: https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-capture-image

azure cannot create vm from vhd image

I'm currently running into difficulty in creating an Azure VM from a custom VM image. I am following the guide from Azure from here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/
I've used Waagent and deprovisioned the machine as instructed, and deallocated, generalized, and captured my machine image (I have made some modifications to the core Ubuntu 16.04LTS image available from Azure software wise). I have successfully created the template.json file (Can provide it if needed). I then completed all the tasks below in the powershell script as outlined in the article, just extracting the parameters to variables to make things a bit easier.
## Global
$rgName = "testrg"
$location = "eastus"
## Storage
$storageName = "teststore"
$storageType = "Standard_GRS"
## Network
$nicname = "testnic"
$subnetName = "subnet1"
$vnetName = "testnet"
$vnetAddressPrefix = "10.0.0.0/16"
$vnetSubnetAddressPrefix = "10.0.0.0/24"
$ipName = "TestIP"
## Compute
$vmName = "testvm"
$computerName = "testcomputer"
$vmSize = "Standard_D1_v2"
$osDiskName = $vmName + "osDisk"
#template
$fileTemplate = "C:\AzureTemplate\template.json"
azure group create $rgName -l $location
azure network vnet create $rgName $vnetName -l $location
azure network vnet subnet create --resource-group $rgName --vnet-name $vnetName --name $subnetName --address-prefix $vnetSubnetAddressPrefix
azure network public-ip create $rgName $ipName -l $location
azure network nic create $rgName $nicName -k $subnetName -m $vnetName -p $ipName -l $location
azure network nic show $rgName $nicname
azure group deployment create $rgName $computerName -f $fileTemplate
I am able to successfully run all the commands to create the resource group and the network components, however, when I try to run the deployment command at the bottom of the powershell script, I get the following and it just hangs here indefinitely. Am I using the right approach to create a VM from a custom image? Or is that Azure guide outdated?
azure group deployment create $rgName $computerName -f $fileTemplate
[32minfo[39m: Executing command [1mgroup deployment create[22m
[32minfo[39m: Supply values for the following parameters
EDIT: Link to image showing the issue: http://imgur.com/a/Fgh8K
I believe your understanding is not complete. If you see at the last line it says Supply values for the following parameters
You need to pass the values for VM name, the admin user name and password, and the Id of the NIC you created previously. My be you should re-read the documentation. Here is the screenshot for your reference from https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/#deploy-a-new-vm-from-the-captured-image -

Resources