Scheduled Virtual Machine Shutdown/Startup

Automates the scheduled startup and shutdown of Azure virtual machines. Schedules are implemented by tagging VMs or resource groups with individual simple schedules. Schedules can define multiple time periods for shutdown, including time ranges and days of week or dates.

 
 
 
 
 
4.7 Star
(21)
59,796 times
Add to favorites
Windows Azure
2/29/2016
E-mail Twitter del.icio.us Digg Facebook
  • Add-AzureAccount : No subscriptions are associated with the logged in account in Azure Service Management (RDFE)
    1 Posts | Last post March 07, 2020
    • I keep getting this error. I have followed the setup instructions and even made the account a subscription owner. 
      
      Any Help would be great.
      
      FULL ERROR:
      
      Add-AzureAccount : No subscriptions are associated with the logged in account in Azure Service Management (RDFE). This means that the logged in user is not an administrator or co-administrator for any account.\r\nDid you mean to execute Connect-AzureRmAccount? At line:322 char:16 + $account = Add-AzureAccount -Credential $azureCredential + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Add-AzureAccount], ArgumentException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
  • Sometimes not detecting the day
    1 Posts | Last post March 21, 2019
    • I've had this problem two weeks in a row, same time each week. It'll stay down all weekend except 8pm - 10pm Saturday & Sunday
      
      Here's an example from 7 pm
      Current EST time [Sunday, 2019 Mar 17 19:00:59] will be checked against schedules
      [AZKSTEST1]: Found direct VM schedule tag with value: 10 PM -> 6 AM, Saturday, Sunday
      [AZKSTEST1]: Current time [03/17/2019 19:00:59] falls within the scheduled shutdown range [Sunday]
      [AZKSTEST1]: Current power state [deallocated] is correct.
      
      
      
      Current EST time [Sunday, 2019 Mar 17 20:00:52] will be checked against schedules
      [AZKSTEST1]: Found direct VM schedule tag with value: 10 PM -> 6 AM, Saturday, Sunday
      [AZKSTEST1]: Current time falls outside of all scheduled shutdown ranges.
      [AZKSTEST1]: Starting VM
      
      Then it has the same behavior at 9 pm, and here is 10 pm
      
      Current EST time [Sunday, 2019 Mar 17 22:00:11] will be checked against schedules
      [AZKSTEST1]: Found direct VM schedule tag with value: 10 PM -> 6 AM, Saturday, Sunday
      [AZKSTEST1]: Current time [03/17/2019 22:00:11] falls within the scheduled shutdown range [10 PM -> 6 AM]
      [AZKSTEST1]: Stopping VM
      
      Does anyone have ideas about what is causing this behavior and how to fix it?
      
      I did implement a change so that it'd be in EST, but this script works fine all other days/times except 8 - 10 Saturday & Sunday.
  • Fantastic script, how do I submit improvements?
    3 Posts | Last post February 01, 2019
    • I added logic to handle a specified time zone tag. I'm happy to share, but where do I submit the changes?
    • Thanks! The script is being developed here if you'd like to contribute:
      
      https://github.com/automys/Azure-Automation-Scheduled-VM-Shutdown
    • Thanks!
  • Not returning any resource groups when filtering by tag name
    2 Posts | Last post August 30, 2017
    • Hi,
      I'm running into problems with this part of the script.
      $taggedResourceGroups = @(Get-AzureRmResourceGroup | where {$_.Tags.Count -gt 0 -and $_.Tags.Name -contains "AutoShutdownSchedule"}) 
      I'm not getting any resource groups when filtering by Tags.Name. Tags.Count -gt 0 works fine and correctly shows all my resource groups with the "AutoShutdownSchedule" tag names, in fact script works fine with just: $taggedResourceGroups = @(Get-AzureRmResourceGroup | where {$_.Tags.Count -gt 0}).
      
      Windows 10, Azure PS 2.0.1.
    • I experienced the same behavior after updating the modules (AzureRM.Automation is version 3.3.1).
      
      Just change 
      .Tags.Name to .Tags.Keys 
      @$shedule change 'WHERE Name' to 'WHERE Keys' 
      ["Value"] to .Values
      
      Best regards
      Valerian
  • mostly suerpceeded by new 'autoStop VM' feature added to Azure portal:
    1 Posts | Last post March 17, 2017
    • https://portal.azure.com/#resource/subscriptions/{subscriptionid}/resourceGroups/{resourcegroupdname}/providers/Microsoft.Compute/virtualMachines/{virtualmachinename}/autoStop
  • Script modification for Azure Ressource Manager VM
    2 Posts | Last post February 17, 2016
    • Hi, 
      Some modification on the script to work with new cmdlet (2015-11-13).
      See http://pastebin.com/6KhKWjp7
    • A note for others, this should no longer be necessary with latest version.
  • Keep getting the following error, can you help me solve this?
    3 Posts | Last post July 10, 2015
    • Error: Add-AzureAccount : unknown_user_type: Unknown User Type
      At shutdown-vm:41 char:41
      + 
          + CategoryInfo          : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
          + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
      
      
      Credential Name: azureautotest
      
      I didn't use the full name (azureautotest@_____.onmicrosoft.com)
    • Hi there. Just to confirm, you need to use an Azure AD account, and not a standard Microsoft account. It looks like that's the case based on the username. That said, the username in the credential does need to be the fully-qualified name with the domain suffix. The credential name can be anything, but needs to be specified in the runbook scheduled run parameters so that it looks for that credential. Does that help?
    • Hi Noah, 
      
      Thank you for the tips. It's working now. Much Appreciated.
      
      TauseefK