Update October 2019:
Since March 2019, Azure Schedulers support the selection of weekdays. The article will still be available because weekday selections are only an example of custom control flows and parameters.

Often the first workload in the cloud is a VM. If this VM runs 24 hours a day, you usually calculate 730 hours running time per month (365/12 days per month) and pay for this 730 hours. However, if the machine is only used 10 hours a day and maybe not even on weekends, the runtime is reduced to 217 hours:

365 12 7 5Weekdays 10h per Day = 217,26

This corresponds to a saving of 70%!

With Azure Automation, jobs for starting or stopping VMs can be executed time based. Scheduling can be repeated, but only by hours, days, weeks, or months. Unfortunately, there is no scheduling for weekdays. Thanks to PowerShell, this is recorded in a few lines as an additional parameter during scheduling and can be used. The excerpt from the script then shows:

...
param (
    [Parameter(Mandatory=$false)] 
    [String]  $AzureConnectionAssetName = "AzureRunAsConnection",

    [Parameter(Mandatory=$false)] 
    [String] $ResourceGroupName,
	
    [Parameter(Mandatory=$false)] 
    [String]  $Weekdays = "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"
)

Write-Output "checking weekday:"
$now = Get-Date
$weekday = $now.DayOfWeek
Write-Output "today is $weekday"
If (-Not ($Weekdays -like -join("*",$weekday,"*")))
{
	Write-Output "stop, not the requested weekday"
	return
}
Write-Output "start... (weekday check passed)"
...
  • Line 10 defines the parameter for the weekdays. Here I have set all 7 weekdays as default value, i.e. the script can be executed every day.
  • Line 17 checks whether the current day of the week is included in the list of parameters. If this is not the case, the script ends.

Its realy easy to customize the Start/Stop scripts for using weekdays. The whole scripts can be found at my GitHub repo: https://github.com/tzuehlke/scripts/tree/master/AzureAutomation