Schedule startup and shutdown of your virtual machines using Azure Automation

Written by ppolyzos

Software engineer based in Athens, Greece

17 Comments

    1. ppolyzos

      You can specify the VMs you want to start or stop using a comma separated string array, like ‘AzureVm1,AzureVM2’ and then perform a loop for each VmName.
      So, you can do something like:

  1. Eli Rios

    How do you properly replace the parameters for the variables?
    Do I have to change [string]$VmName, with the name of my server like this [AzureVM-Srv1]$VmName or without brackets? or AzureVM-Srv1 = $VmName?

    1. ppolyzos

      If I understand correctly your question, if you want to define your server name in VmName, you only to update VmName with AzureVM-Srv1 as shown in Step4.
      What is inside the brackets is to add additional information about the variable, like string or validation like [ValidateSet(“Startup”, “Shutdown”)]. You can have a look also here to learn more about Powershell parameters.

    2. Andre

      hi Eli, you set the parameters when you create the schedule task. You dont need to change anything in the code.
      You can set parameters in test panel also.

  2. moin

    Grate jobs thanks from bottom of my heart , As well i if you help me with few other parameters like i want to run same with multiple selected vm, where and how to add parameters.

  3. moin

    Thanks for the quick response. as i am not an expert in powershell, Could you please tell me where and how to make changes in current script as current script work for only one vm i want to use same for multiple vms i should have option to specifie or selcet the vm’s to start and stop.

    1. ppolyzos

      I understand now what you want to achieve. Have list a list of VM names and with a single script start them or shut them down.
      You can use a string array parameter, like: param([string[]] $VmName......) and then iterate on the $VmNames. Have a look as well here

      And for VMName you can pass multiple string comma separated like: Vm1,Vm2,Vm3....

      Be aware that I haven’t tested the script above but it should work or it may require some minor changes.

      1. moin

        Thank you so much for the help .after making some changes it is working now…..i have one more question Sir. Suppose i have to automate vm creation at particular time. everyday vm should be created automatically using run book. is it possible ?

Leave a Comment

Your email address will not be published. Required fields are marked *