Automatically run custom scripts when starting the VM ?

SirWin 1 Reputation point

I use the following command to run when creating the VM. But when the VM reboots, it no longer executes.
How to set the script to run each time the VM is started.

az vmss extension set \
--vmss-name VM1 \
--resource-group myResourceGroup \
--publisher http://Microsoft.Azure.Extensions \
--version 2.0 \
--name CustomScript \
--settings '{"commandToExecute":"sudo sysctl -w vm.nr_hugepages=512"}'


Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,569 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 17,351 Reputation points MVP


    You need to upload your scripts inside a storage account or Github, then get the URL. Modify the procedure so that it access the location and get the script when the VM reboots

    Please mark as "Accept the answer" if the above steps helps you. Others with similar issues can also follow the solution as per your suggestion



  2. SirWin 1 Reputation point

    I tried like this, but it doesn't seem to work.
    --settings '{"fileUris": [""],"commandToExecute": "./"}'

    0 comments No comments

  3. Manu Philip 17,351 Reputation points MVP

    The usage is bit tricky. Ty as following. Save the script inside your storage account share

    --settings '{"fileUris": [""],
    "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File"}'