PowerShell: Shutdown Azure VMs Outside Working Hours

I run some Azure Virtual Machine’s for work stuff (testing, remote access) and non-work stuff (game servers).  The specification is pretty low but I like to shut it down from Azure to reduce any charges from it.  This might lose their currently allocated IP address (they might get a different one on restart) but that’s not an issue for me.  Over the weekend is a good time as I almost never use Azure then.

Unfortunately my memory is pretty rubbish especially during the Friday afternoon excitement/rush.  What I want is a script that will run on my home machine, check the time and then shut my VMs down if we’re out of working hours.

The script follows with the explanation afterwards. Continue reading “PowerShell: Shutdown Azure VMs Outside Working Hours”