I am unable to find a way to remove a host name from a azure web app/app service.
I have tried to use the following filtering our unwanted hosts, but nothing is removed.
Set-AzureWebsite -Name "<<name>>" -HostNames $hosts
and
Set-AzureRmWebApp -Name "<<name>>" -ResourceGroupName "<<name>>" -HostNames $hosts
I have around 200 hosts to delete, however, I can't seem to find an automated way of doing it.
at a top level this is what you need to do:
Here is an example of how I did it:
$webApp = Get-AzureRmWebApp -ResourceGroupName "<<Resource-Group-Name>>" -Name "<<App_Name>>"
$webApp.HostNames.Clear()
$webApp.Hostnames.Add($webApp.DefaultHostName)
set-AzureRmWebApp -ResourceGroupName "<<Resource-Group-Name>>" -Name <<App_Name>> -HostNames $webApp.HostNames
This will remove all custom hostnames and leave only the default one.
If you want to remove a specific hostname for the collection you could use:
$webApp.HostNames.Remove("your_hostname_goes_here")
NOTE If your hostname has SSL bindings you will need to remove those first and then delete the hostname.