0

On Azure, I'm using Scale Set with PowerShell DSC to run a script to configure my VMs every time a new one is created. But now I need to run a powershell script every time a VM is deleted from the scale set. How can i do that?

Victor Balbo
  • 63
  • 1
  • 9

1 Answers1

1

You should be able to register a script to run on shutdown with the Group Policy Editor like this: http://lifehacker.com/use-group-policy-editor-to-run-scripts-when-shutting-do-980849001. However, currently scale sets don't guarantee that your code will have time to run before the VM delete actually happens; this is on the backlog, however, so hopefully we'll have this functionality soon.

Hope this helps! :)

Neil Sant Gat
  • 857
  • 6
  • 10
  • This is specific to Windows. How about Linux? This is anyway a runlevel programming. – Jaydeep Ranipa Mar 19 '18 at 11:29
  • Just like it has Custom Script extension for VMSS, does it have anything to run before the VMSS scales in any instance? Say I want to backup some log data before the particular VM is destroyed by VMSS for scaling. – Jaydeep Ranipa Mar 19 '18 at 11:31
  • The same applies for Linux. You can write code in the VM to catch the shutdown signal (like this: https://github.com/gatneil/demos/blob/master/onstartstop-linux/deployvm.sh), but currently there is no guarantee the scale set will give your code any time to run before the VM gets deleted. – Neil Sant Gat Mar 20 '18 at 18:58
  • @NeilSantGat Is this still "in the backlog" or has the feature been delivered? – BrettJ Sep 29 '20 at 14:46
  • It looks like this feature landed in a form May 2020 "Termination Notification" - https://azure.microsoft.com/en-us/blog/azure-virtual-machine-scale-sets-now-provide-simpler-management-during-scalein/ – BrettJ Sep 29 '20 at 20:45