forked from FBoucher/AzurePowerTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShutDown-AllVMs.ps1
28 lines (19 loc) · 1021 Bytes
/
ShutDown-AllVMs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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
}