Configure VM on/off schedules for RDSMgmt and RDSGW

Migrate from MCIT classic (v2) schedule to Azure native schedules for core servers

If you are using MCIT classic (v2) scheduler to turn off and on the RDSMgmt or RDSGW servers and you want to use it natively in Azure follow this guide. 

Warning: this article does not apply to scheduling or autoscaling RDS session hosts or to natively created v3 deployments. To schedule or auto scale session hosts create a policy via autoscale tab at https://mycloudit.io

Part 1: Clean Up MCIT classic schedules

  1. Navigate to https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Automation%2FAutomationAccounts
  2. Select the automation account that is located in the same resource group as you MCIT RDS deployment
  3. Select the Runbooks blade and delete all existing MCIT classic runbooks
  4. Select the Schedules blade and delete all existing MCIT classic schedules

Part 2: Configure new runbook to turn on VM's

  1. Navigate to https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Automation%2FAutomationAccounts
  2. Select the automation account that is located in the same resource group as you MCIT RDS deployment
  3. Select the Runbooks blade and "create a runbook"
  4. Enter the following details:
    1. Name: Runbook-Start
    2. Runbook type: Powershell
    3. Runtime version: 5.1
  5. Click create and wait for the edit powershell runbook clade to come up
  6. Paste in the following code:
    1. # To Start
      $Conn = Get-AutomationConnection -Name AzureRunAsConnection
      Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
      $VMs = Get-AzureRMVM | where { $_.Tags.Values -like '*RunbookStart*' -And ($_.Tags.Values -like '*RDCB*' -Or $_.Tags.Values -like '*RDGS*') }
      $VMs | Start-AzureRMVM
      Write-Output $VMs.Name
  7. Click Publish and Yes
  8. Click link to schedule
  9. Click Schedule
  10. Click add a schedule
  11. Create a schedule as per your needs,
    1. Type title as: Schedule-Start
    2. Select starts as tomorrows date
    3. Select time as the time you want the RDSGW and RDSMgmt to turn on
    4. Choose appropriate time zone
    5. Select "recurring"
    6. Select week
    7. Tick the days of the week you want to turn on the RDSMgmt and RDSGW
    8. Click create
  12. Click Ok

Part 3: Configure new runbook to turn off VM's

  1. Navigate to https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Automation%2FAutomationAccounts
  2. Select the automation account that is located in the same resource group as you MCIT RDS deployment
  3. Select the Runbooks blade and "create a runbook"
  4. Enter the following details:
    1. Name: Runbook-Stop
    2. Runbook type: Powershell
    3. Runtime version: 5.1
  5. Click create and wait for the edit powershell runbook clade to come up
  6. Paste in the following code:
    1. # To Stop
      $Conn = Get-AutomationConnection -Name AzureRunAsConnection
      Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
      $VMs = Get-AzureRMVM | where { $_.Tags.Values -like '*RunbookStop*' -And ($_.Tags.Values -like '*RDCB*' -Or $_.Tags.Values -like '*RDGS*') }
      $VMs | Stop-AzureRMVM -Force
      Write-Output $VMs.Name
  7. Click Publish and Yes
  8. Click link to schedule
  9. Click Schedule
  10. Click add a schedule
  11. Create a schedule as per your needs,
    1. Type title as: Schedule-Stop
    2. Select starts as tomorrows date
    3. Select time as the time you want the RDSGW and RDSMgmt to turn off (deallocate)
    4. Choose appropriate time zone
    5. Select "recurring"
    6. Select week
    7. Tick the days of the week you want to turn off the RDSMgmt and RDSGW
    8. Click create
  12. Click Ok

Part 4: Configure the VM tags for RDSMgmt

  1. Navigate to https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Compute%2FVirtualMachines
  2. Select the RDSMgmt (sometimes named something similar like RDSMgmt-1)
  3. Select the Tags blade
  4. Add a new tag Named RunbookStart with value RunbookStart (see below screen shot)
  5. Add a new tag Named RunbookStop with value RunbookStop
  6. Click Apply

Part 4: Configure the VM tags for RDSGW

  1. Navigate to https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Compute%2FVirtualMachines
  2. Select the RDSGW (sometimes named something similar like RDSGW-001)
  3. Select the Tags blade
  4. Add a new tag Named RunbookStart with value RunbookStart
  5. Add a new tag Named RunbookStop with value RunbookStop
  6. Click Apply