Update Azure Website instance size (Small, Medium, Large) with Powershell - powershell

Is there a way to scale an Azure WebSite instance size (not instance count) using PowerShell? I haven't found the way.
I know it can be done using Azure CLI or from the Portal, but I want to be able to do it with PowerShell. Is this posible?
I want to update an existing WebSite instance size, not create a new website.

Yes, you first need to know the name of the Resource Group and Web Hosting Plan to which your website belongs, which you can get from the new Azure Portal. Then you can change the worker size to 0 (Small), 1 (Medium) or 2 (Large).
Switch-AzureMode AzureResourceManager
$resourceGroup = "MyResourceGroup"
$webHostingPlan = "MyWebHostingPlan"
$whp = Get-AzureResource `
-Name $webHostingPlan `
-ResourceGroupName $resourceGroup `
-ResourceType "Microsoft.Web/serverFarms" `
-ApiVersion 2014-04-01
$newWorkerSize = 1
$whp.Properties.workerSize = $newWorkerSize
$whp.Properties.workerSizeId = $newWorkerSize
Set-AzureResource `
-Name $webHostingPlan `
-ResourceGroupName $resourceGroup `
-ResourceType "Microsoft.Web/serverFarms" `
-ApiVersion 2014-04-01 `
-PropertyObject $whp.Properties

Related

Creating OS disk from VHD stored in another storage account

Have an existing PowerShell script that is creating VM's using pre-created VHD's stored in a storage account (copied across regional storage accounts for speed).
In PS we can use the following:
New-AzureRmDisk -DiskName $osDiskName -Disk `
(New-AzureRmDiskConfig -AccountType Premium_LRS `
-Location $location -CreateOption Import `
-StorageAccountId $storageAccountId `
-SourceUri $osVHDUri) `
-ResourceGroupName $resourceGroupName
$osDisk = Get-AzureRMDisk -DiskName $osDiskName -ResourceGroupName $resourceGroupName
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $osDisk.Id -CreateOption Attach -Windows -StorageAccountType Premium_LRS
Where $storageAccountId is similar to:
/subscriptions/{0}/resourceGroups/my-snapshot/providers/Microsoft.Storage/storageAccounts/mysnapshots -f $sourceSnapshotSubscriptionId
In the .net Azure SDK, I don't see a way to replicate this? When I try to create, it's saying unable to find, yet my PS works ok.
If you want to use an existing disk instead of a marketplace image, use this code:
var managedDisk = azure.Disks.Define("myosdisk")
.WithRegion(location)
.WithExistingResourceGroup(groupName)
.WithWindowsFromVhd("https://mystorage.blob.core.windows.net/vhds/myosdisk.vhd")
.WithSizeInGB(128)
.WithSku(DiskSkuTypes.PremiumLRS)
.Create();
azure.VirtualMachines.Define("myVM")
.WithRegion(location)
.WithExistingResourceGroup(groupName)
.WithExistingPrimaryNetworkInterface(networkInterface)
.WithSpecializedOSDisk(managedDisk, OperatingSystemTypes.Windows)
.WithExistingAvailabilitySet(availabilitySet)
.WithSize(VirtualMachineSizeTypes.StandardDS1)
.Create();
Check this link for further reference. Hope it helps.

How To Configure TLS Mutual Authentication for Azure Web App through PowerShell?

According to the docs you can set ClientCertEnabled through the ARMClient Tool. You can nowadays also use https://resources.azure.com to do so or even set it as property in ARM Templates.
Is there any possibility to set it directly through Azure PowerShell? I found that retrieving an app through Get-AzureRmWebApp also states if ClientCertificates are enabled or not.
Yes, you can set it on the underlying resource. Sample:
$Resource = Get-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites -ResourceName $resourceName -ApiVersion 2016-08-01
$Resource.Properties.clientCertEnabled = "True"
$Resource | Set-AzureRmResource -Force
HTH

Unable to set SKU using Set-AzureRmResource

I am using Azure PowerShell and using Azure Resource Manager commandlets to set SKU to "Standard". The following examples isn't working
$azsite = Get-AzureRmResource -ResourceType "Microsoft.Web/Sites" -ResourceName "azwebapp" -ResourceGroupName "DefaultResourceGroupName"
$azsite.properties.sku = "standard"
$az | set-azurermresource -Force
The resource still has the free tier.
I also tried.
Set-AzureRmResource -ResourceType "Microsoft.Web/Sites" -ResourceName "azwebapp" -ResourceGroupName "DefaultResourceGroupName" -Sku #{"name" = "standard"} -Force
And still it doesn't change the resource sku to standard.
The best thing is to use the dedicated app service plan cmdlets more over the sku is an app service plan property, you can use the following example
Set-AzureRmAppServicePlan -ResourceGroupName DefaultResourceGroupName -Name <AppServicePlanName> -Tier Standard

Error adding Alert Rule to Azure Cloud Service

I've created a script to add alert rules to several Azure resources (web apps, SQL databases, and cloud services). Everything works except for creating the cloud service alerts which returns an error:
Add-AlertRule : ResourceProviderNotSupported: The resource provider
'Microsoft.ClassicCompute' is not supported.
This is the script I'm using to add the rule:
$cloudServices = Get-AzureResource -ResourceType "Microsoft.ClassicCompute/domainNames" -ResourceGroupName $resourceGroup
Foreach ($cloudService in $cloudServices)
{
# Cloud Service - CPU Percentage
Add-AlertRule `
-RuleType Metric `
-Name "CPU Percentage (Cloud Service)" `
-Location $cloudService.Location `
-ResourceGroup $cloudService.ResourceGroupName `
-Operator GreaterThan `
-Threshold 75 `
-WindowSize 01:00:00 `
-ResourceId $cloudService.ResourceId `
-MetricName "Percentage CPU" `
-TimeAggregationOperator Average `
-SendToServiceOwners
}
I've tried other using a different ResourceType parameter to target the role instead of the cloud service, but that doesn't work either.
Has anyone had any experience scripting these cloud service alerts successfully?
Hi Garrett sometime back I had created same kind of stuff without any issues. Please have a look on this link-
http://blogs.technet.com/b/keithmayer/archive/2014/11/08/scripts-to-tools-automate-monitoring-alert-rules-in-microsoft-azure-with-powershell-and-the-azure-service-management-rest-api.aspx

How to script scaling a Website from Small to Large? [duplicate]

Is there a way to scale an Azure WebSite instance size (not instance count) using PowerShell? I haven't found the way.
I know it can be done using Azure CLI or from the Portal, but I want to be able to do it with PowerShell. Is this posible?
I want to update an existing WebSite instance size, not create a new website.
Yes, you first need to know the name of the Resource Group and Web Hosting Plan to which your website belongs, which you can get from the new Azure Portal. Then you can change the worker size to 0 (Small), 1 (Medium) or 2 (Large).
Switch-AzureMode AzureResourceManager
$resourceGroup = "MyResourceGroup"
$webHostingPlan = "MyWebHostingPlan"
$whp = Get-AzureResource `
-Name $webHostingPlan `
-ResourceGroupName $resourceGroup `
-ResourceType "Microsoft.Web/serverFarms" `
-ApiVersion 2014-04-01
$newWorkerSize = 1
$whp.Properties.workerSize = $newWorkerSize
$whp.Properties.workerSizeId = $newWorkerSize
Set-AzureResource `
-Name $webHostingPlan `
-ResourceGroupName $resourceGroup `
-ResourceType "Microsoft.Web/serverFarms" `
-ApiVersion 2014-04-01 `
-PropertyObject $whp.Properties