How to shut down automatically all your existing VMs

Опубликовано: 07 Май 2026
на канале: Frank Boucher
2,625
20

In this Cloud in 5 minutes episode, I will show you how to shut down automatically every night, all your existing VMs in #Azure using a very simple #PowerShell script once.
Subscribe: http://bit.ly/2jx3uKX

(#cloud5mins - Episode #18 #EN)

POWERSHELL SCRIPT:
-------------------------------------

Login-AzureRmAccount

$Subscription = Get-AzureRmSubscription -SubscriptionName 'SUBSCRIPTION_NAME'

Select-AzureRmSubscription -Subscription $Subscription.Id

#== VM selection =========================
$selectedVMs = Get-Azurermvm -ResourceGroupName cloud5mins

foreach($vm in $selectedVMs)
{
$ResourceGroup = $vm.ResourceGroupName
$vmName = $vm.Name
$ScheduledShutdownResourceId = "/subscriptions/$Subscription/resourceGroups/$ResourceGroup/providers/microsoft.devtestlab/schedules/shutdown-computevm-$vmName"

$Properties = @{}
$Properties.Add('status', 'Enabled')
$Properties.Add('targetResourceId', $vm.Id)
$Properties.Add('taskType', 'ComputeVmShutdownTask')
$Properties.Add('dailyRecurrence', @{'time'= 2100})
$Properties.Add('timeZoneId', 'Eastern Standard Time')
$Properties.Add('notificationSettings', @{status='Disabled'; timeInMinutes=60})

New-AzureRmResource -Location $vm.Location -ResourceId $ScheduledShutdownResourceId -Properties $Properties -Force
}


USEFUL LINKS
------------------------

Previous Video: Comment éteindre automatiquement une VM dans Azure -    • Comment éteindre automatiquement une VM da...  

Blog post: How to save huge money by shutting down your VM automatically - http://www.frankysnotes.com/2018/02/s...


FOLLOW ME ON
--------------------------

Twitter: twitter.com/fboucheros
Linkedin: linkedin.com/in/fboucheros
Facebook: fb.com/frankysnotes


BLOGS
------------

Cloud en Francais (FR): http://www.cloudenfrancais.com
Frankys Notes (EN): http://www.frankysnotes.com

GEARS
------------

Camtasia 9: http://amzn.to/2DK38bP
Logitec C922 PRO: http://amzn.to/2DMcTX4
Blue Snowball: http://amzn.to/2FqemTi



-