Manage Azure websites from PowerShell.

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp


When we have to manage our Azure web portals Normally we go to the web portal that allows us to manage everything visually and quite intuitively. But we must not forget that we can also manage it through Windows PowerShell that will allow us to make changes in a more technical and precise way, being able to make changes to all our websites with a single line of code.

To start our journey with Azure PowerShell, we will briefly and concisely explain what we call “PowerShell”, this is nothing more than a command console much more complete and advanced than “MS-DOS” O “CMD”, that will allow us to fully manage our computers with Windows operating system. The distinctive feature of PowerShell is that it is an object-oriented shell. The input and output information at each stage of the process is a set of object instances, unlike what happens with traditional command interpreters, that only return and receive text.


What is Azure PowerShell?

It is a module that offers cmdlet (“Commands”) to manage our Azure subscriptions through PowerShell. We can configure, create and manage the solutions and services that Azure offers us. Everything we can do through the Azure portals can also be configured through the cmdlet that this module provides us.

Instalar Azure PowerShell

To start using Azure PowerShell, the easiest and fastest way is to download the following installation file “Azure PowerShell will show us a list of applications that, in our case, we will install "Microsoft Azure PowerShell"That will add the necessary cmdlets to be able to connect to Azure from a PowerShell console.


First steps

We open PowerShell and before connecting to Azure we must verify that our module “Azure PowerShell” has been successfully installed on our machine.

# We show the list of modules that we have installed
Get-Module –ListAvailable
# If it doesn't show us the Azure PowerShell module, we must import it
Azure import module

Then, we are going to connect with our credentials:
#Log in to Azure



Manage Azure websites

To select the subscription that we are interested in managing, We will see the list of subscriptions that we have available with our credentials and we will select the one in which the portals that we are going to manage are hosted.

# See the list of subscriptions we have associated with our credentials.


# We select the subscription.
Select-AzureSubscription “Subscription name”
# List of Azure websites for the selected subscription.


# Shows detailed information of a website.

Get-AzureWebsite –Name “Website name”


All this information that it does not display can be stored in a variable that, using the tab, we can go through all its properties.
# We store the website data in a variable.
$ variable = Get-AzureWebsite –Name “Website name”
# We configure the portal with the data that we have modified in the object.
Set-AzureWebsite –Name “Name of the website” –SiteWithConfig $ variable

The easiest way to modify several of the properties of a website is by modifying the object that we have stored in a variable and using it as a parameter in the command “Set-AzureWebsite”. We can perform more administration tasks with the different parameters of “Set-AzureWebsite”.

We can use tubes “|” to perform an action for all the websites of our subscription.
#For all the portals of our subscription.
Get-AzureWebsite | Stop-AzureWebsite


Create an Azure website

We can create in an instant a website with the name and location that we want by following the following lines:
# List of locations available for our website.
Get-Azure website location
#Check if the name we have chosen for our portal is busy. If it is false, the name is available.
Test-AzureName – Website “Website name”
#Create our Azure website with the data we have provided by parameters.
New-AzureWebsite – Location “Location name” – Name “Website name”


Delete a website from Azure

There is nothing easier than deleting a website from Azure using commands, to do it you just have to execute the following:

# List of locations available for our website.
Remove-AzureWebsite –Name "Website name".


And if we want to remove all Azure websites from our subscription we will use the following method:

# List of locations available for our website.
Get-AzureWebsite | Remove-AzureWebsite.

In summary, Azure PowerShell is one of the most powerful tools that Microsoft offers us to administer and manage your environment in the cloud. In future publications we will discover commands and scripts that will help us to optimize our services in Microsoft Azure.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.