En visitant ce site, vous acceptez le fait que nous utilisons des cookies.
Accept
Akril.netAkril.net
  • Apple
  • Cloud
    • Amazon AWS
    • Google Cloud Platform
    • Microsoft Azure
  • Google
  • Microsoft
    • Microsoft Azure
    • Microsoft Office
    • Microsoft Office 365
    • Microsoft SQL Server
    • Microsoft System Center
    • Microsoft Windows
    • Microsoft Windows Server
    • PowerShell
  • Linux
  • Sécurité
    • Varonis
  • Geek
    • Bitcoin
    • Citrix
    • Hardware
    • Jeux-vidéo
    • Logiciels et Applications
    • Photographie
    • Raspberry Pi
    • Smartphone
    • Virtualisation
    • Web
    • VMware
  • English
  • A propos
  • Contact
    • Annonceurs
Notification Show More
Latest News
CyberSecurity-Logo
BreachForums : le plus gros vendeur de données illégales en ligne, arrêté par le FBI
Sécurité
Carte-Sim-Logo
Après la nano-SIM, la eSIM s’apprête à remplacer la iSIM
Smartphone
UK-Flag
Disparition de WhatsApp et Signal au Royaume-Uni
Web
Headsets-Logo
Test des casques Nuroum HP20 et Plantronics Blackwire 5220
Hardware
Pourquoi louer un studio photo pour un shooting en famille ?
Photographie
Akril.netAkril.net
Recherche
Follow US
AKRIL.NET - Copyright © 2006-2023. All Rights Reserved.
Akril.net > Cloud Computing > Microsoft Azure > Auto start and shutdown a VM in Azure to improve cost management
Microsoft AzureEnglish

Auto start and shutdown a VM in Azure to improve cost management

thibault
Dernière mise à jour : 08/10/2022
par thibault Published 19 mai 2018
Partager
8 Min Read
Partager
The method described in this article is obsolete. It won’t work anymore in Microsoft Azure. Consult another alternative described in this article.

When you want to use cloud computing solutions from AWS, Azure, Google Cloud Platform or any others. You will probably need at some point a virtual machine. And what’s the most interesting with Cloud providers is that you will pay only for what you’re using. That’s mean that if you can automate the shutdown or the start of a Virtual Machine, you will be billed only for the moment when the VM is running.

When your VM is executed, you will be billed for everything: CPU, power, RAM and every resources you’re using but also storage. When the VM is shutdown, you will be billed only for the storage that is generally a lot less expensive.

In my scenario, I have several Azure subscriptions with a few amount of credits. The interest for me is to be able to use it exactly for what I need and shutdown things when I don’t use it in order to save my credit ! 🙂

Let’s check how we can do this in the Microsoft Cloud: Azure.

Create your virtual machine

First, create a test virtual machine and think about when you will need it. In my example, I want to create a virtual machine that I will use as a low-cost remote virtual desktop when I’m moving and bringing only my Chromebook or iPad (and need Windows Apps).

So, I will choose the latest version of Windows 10, hostname, subscription, location, resource group but also, I will use (automatically) the « Azure Hybrid Benefit« . That’s mean, you can avoid to paid the licence of a Windows Server or Desktop if you bring / use licences that you’re already owning. In general, you can save up to 40% of the standard cost for the same virtual machine with an integrated paid licence in Azure.

For my needs, I will use the size : B4ms with 16 GB of RAM and 4 vCPUs. More information on the B-Series introduced by end of 2017, by following this link. Should be quite enough for my usage scenario.

Automatically schedule the shutdown of your VM

To be able to process automatically the shutdown of your virtual machine, it’s quite easy with Azure. The best way to do this is to configure the specific option when you’re creating your virtual machine.

Do not forget to choose the time zone that will correspond to your country. In the above example, I have selected to automatically shutdown the VM at 10.30 AM but choose the schedule that will suit to your personal needs.

You can also to choose to receive an email a moment before the automatic shutdown. This option might be useful if for example you may want to delay the shutdown on a specific day. Because, you will be able to postpone directly in the mail notification you will receive.

Automatically start the virtual machine (on scheduled time)

To be able to automatically start your virtual machine on specific time we will need an Automation Account. Create a new Automation Account in your same Resource group where you’ve created your virtual machine. No specific option, just create it.

Note that this service is also a paid service but it’s a lot less expensive than running your virtual machine every day in one month. Besides, for a short script that will just start our VM: it will be free ! 😉

When your Automation Account is created. Go in it in Azure. Choose in the sub-menu « Process Automation » and go in « Runbooks« . You will find a set of default scripts but we will create a new one.

Select Add a runbook.

Select the option Create a new runbook. Choose a name, PowerShell Workflow and a description. Finalize with the button Create.

Then, click on the Edit button to create our code. You will see that it will be very easy. Insert the 3 lines in you scripts between the brackets.


workflow StartVM-NyX
{
# Association to the Azure subscribtion
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

# Start the virtual machine
Start-AzureRMVM -ResourceGroupName "TGI-Perso" -Name "VM-Hostname"
}

In my example : TGI-Perso is my Resource Group. Don’t forget to adapt according do your settings. Same thing for the name of your virtual machine and the name of your workflow.

Save and Publish you script (top buttons).

Then, on the left go in the Schedules options. Select Add a Schedule. Choose the option Link a schedule for your runbook. After, Create a new schedule.

Give it a name, a description. Choose a time of beginning, a time zone and the recurrence.

Now, your schedule is correctly linked to your script. You can just adapt the time to be able to test right now or you can wait the next execution time to see if your virtual machine will be started or not.

Later, you can also check in your Activity Log tab. For example, if I’m looking on my specific VM I can see that it has been started and stopped on daily basis as expected automatically. This management helps me to save money on my Azure subscription.

In the above example, it corresponds to a VM that I’m using for a TeamSpeak server that is started only during the evening + night a few hours (and not the whole day).

Example of cost management

If I’m taking back the example of my VM: B4ms. The cost by month announced by Microsoft is: 121,97  €. Let’s say one month is 31 days and one day is 24 hours. We have 744 hours / month. The cost of 121.97 € will be 744 hours / month.

But, if I’m running only my VM from 10:00 AM to 1.00 AM each day. It will be like 16 hours a day. For 31 days x 16 hours it will be something like: 496 hours. In this logic, the price of this virtual machine will cost me something like 81 € which means it is 30 % less expensive.

It’s an example and maybe when you will read this article pricing would have been updated by Microsoft for my example. But the point is that these 3 lines of code, can help you to decrease by more than 30 % the cost of your virtual machine (or save on your Azure credits)! 😉


TAGS : Automation, Azure, PowerShell, shutdown, start
Partager cet article ?
Twitter Whatsapp Whatsapp LinkedIn Telegram Email Copy Link
Vous en pensez quoi ?
Love0
Happy0
Embarrass0
Sad0
Angry0
4 commentaires

Publicités

Auteur

Cloud Solution Architect – Engineering (aka. Sr. Premier Field Engineer – PFE) @ Microsoft dans les domaines de l’infrastructure, du cloud et de la sécurité. Je suis également passionné par tout ce qui concerne les nouvelles technologies ainsi que la photographie ! Bonne visite ! 🤓

Follow @akril
Girl in a jacket

Dernière vidéo YouTube

https://youtu.be/-hQdddZeaNs

Certifications

Certifications

Publicités

Partenaires

Autres articles

Logo-Make.com
Web

Utiliser Make.com pour publier automatiquement sur Twitter ou LinkedIn

thibault thibault 26 février 2023
Azure-Logic-App-Logo
Microsoft AzureCloud Computing

Azure Logic App : publier automatiquement un article WordPress sur Twitter et LinkedIn

thibault thibault 11 février 2023
OpenAI-Logo-Blog
Microsoft AzureCloud ComputingWeb

ChatGPT : innovation et conséquences

thibault thibault 11 février 2023
Microsoft AzureCloud ComputingFeatured

Création d’un environnement de formation avec Azure Lab Services

thibault thibault 29 décembre 2022

Derniers articles sur Microsoft Azure

Azure-Logic-App-Logo
Azure Logic App : publier automatiquement un article WordPress sur Twitter et LinkedIn
Microsoft Azure Cloud Computing
OpenAI-Logo-Blog
ChatGPT : innovation et conséquences
Microsoft Azure Cloud Computing Web
Création d’un environnement de formation avec Azure Lab Services
Microsoft Azure Cloud Computing Featured

Effectuer une recherche ?

Me contacter

Pour me contacter, il vous suffit d’utiliser le formulaire disponible sur la page de contact.

Derniers articles sur Varonis

Classify and locate important documents
English Varonis
Execute a PowerShell script in Varonis DatAlert
English Varonis

Derniers articles sur Citrix

Créer des comptes et groupes de tests dans Active Directory
PowerShell Microsoft Windows Server
Rechercher dans les GPO de votre Active Directory avec PowerShell
PowerShell
winget : un gestionnaire de paquets sur Windows 10
PowerShell
Akril.netAkril.net
Follow US

AKRIL.NET - Copyrights © 2006-2023

Welcome Back!

Sign in to your account

Lost your password?