自動シャットダウンをコマンドを使用して設定および確認する方法

Last Update:
このエントリーをはてなブックマークに追加

こんにちは、Japan Developer Support Core チームの山田です🗻

Azure VM の自動シャットダウン機能は、コストを削減する上で非常に役立つ機能です。
以下の記事で紹介しているように、Azure VM の自動シャットダウン機能は、内部的に Azure DevTest Labs と呼ばれるサービスの Schedule 機能を利用しています。
自動シャットダウンを設定する際に必要な最小権限について | JPDSC Blog

本記事では、よくお問合せいただく、コマンドから自動シャットダウン機能の設定および確認を行う方法を紹介します。 コマンドから行う方法としては、以下の 3 通りの方法があります。

  • Azure CLI
  • Azure PowerShell
  • REST API

上記のいずれも、確認できる内容や設定できる内容に特に違いはありません。
そのため、普段ご利用されている方法に合わせていずれかの方法を選択してご利用ください。
以下にそれぞれの具体的な実行例を案内します。
Azure CLI にて自動シャットダウンの設定を確認する方法
Azure CLI にて自動シャットダウンを設定する方法
Azure PowerShell にて自動シャットダウンの設定を確認する方法
Azure PowerShell にて自動シャットダウンを設定する方法
REST API にて自動シャットダウンの設定を確認する方法
REST API にて自動シャットダウンを設定する方法

前提

自動シャットダウンは、以下の形式でリソースが作成されます。 したがって、各コマンドを実行する際は、このリソースを対象として操作を行うことになります。

1
/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}

また、本ブログでご紹介するパラーメーターの意味合いは以下のとおりです。

  • {SubscriptionId}: Azure VM が属する対象のサブスクリプション ID
  • {ResourceGroupName}: Azure VM が属する対象のリソースグループ名
  • {VMName}: 対象の Azure VM 名

Azure CLI にて自動シャットダウンの設定を確認する方法

az resource show にて、下図の設定を確認してみましょう。

自動シャットダウン設定がオンの際の取得例

コマンド実行例

1
az resource show --ids /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}

出力例(自動シャットダウン リソースが存在し設定がオンの場合):

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
28
29
30
31
32
33
{
"extendedLocation": null,
"id": "/subscriptions/{SubscriptionId}/resourcegroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"identity": null,
"kind": null,
"location": "japaneast",
"managedBy": null,
"name": "shutdown-computevm-{VMName}",
"plan": null,
"properties": {
"createdDate": "2026-01-19T05:27:08.2683332+00:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"notificationLocale": "ja",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Enabled",
"targetResourceId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"resourceGroup": "{ResourceGroupName}",
"sku": null,
"tags": null,
"type": "microsoft.devtestlab/schedules"
}

出力例(自動シャットダウン リソースが存在しているが設定がオフの場合):
自動シャットダウン設定がオフの際の取得例

以下の返答結果から "status": "Disabled"、つまり自動シャットダウンの設定がオフであることを確認できます。

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
28
29
30
31
32
33
{
"extendedLocation": null,
"id": "/subscriptions/{SubscriptionId}/resourcegroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"identity": null,
"kind": null,
"location": "japaneast",
"managedBy": null,
"name": "shutdown-computevm-{VMName}",
"plan": null,
"properties": {
"createdDate": "2026-01-19T05:27:08.2683332+00:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"notificationLocale": "ja",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Disabled",
"targetResourceId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"resourceGroup": "{ResourceGroupName}",
"sku": null,
"tags": null,
"type": "microsoft.devtestlab/schedules"
}

出力例(自動シャットダウン リソースが存在しない場合):
自動シャットダウン リソースが存在しない場合、Azure Portal では下図のように表示されますが、コマンドの返答結果から Not Found エラーが返却されます。
自動シャットダウン リソースが存在しない際の取得例

1
2
3
4
5
6
{
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'microsoft.devtestlab/schedules/shutdown-computevm-{VMName}' under resource group '{ResourceGroupName}' was not found."
}
}

Azure Portal 上において、既定では、自動シャットダウン リソースは非表示となっています。
そのため、もし Azure Portal より自動シャットダウン リソースの存在有無について確認する必要がある場合は、VM が属する対象のリソース グループにて [ビューの管理\非表示項目の表示] を選択して、自動シャットダウン リソースをご確認ください。 Azure Portal から自動シャットダウン リソースを表示させる方法

Azure CLI にて自動シャットダウンを設定する方法

  • az vm auto-shutdown にて、自動シャットダウン スケジュール (リソース) を作成/削除することが可能です。
  • 既存の自動シャットダウン リソースの設定が存在する場合、新しい設定に上書きされます。
  • "(UTC+09:00) 大阪、札幌、東京" などの任意のタイムゾーンの指定はできないため、UTC 時刻で指定する必要がある点にご留意ください。
  • 省略可能な --email および --webhook パラメーターを省略した場合、既存の設定は削除される点にご留意ください。(例: 元々自動シャットダウンの設定において電子メール アドレスを設定していた状態で、--email パラメーターを省略してコマンドを実行すると、既存の電子メール アドレスの設定値が削除されます。)
  • --off パラメーターにより自動シャットダウン スケジュールを削除する際は、自動シャットダウン リソース自体も削除されるため、後から元の設定値に戻すことができない点にご留意ください。

コマンド実行例 (自動シャットダウン スケジュール作成)

1
az vm auto-shutdown -g {ResourceGroupName} -n {VMName} --time 1730 --email "foo@bar.com" --webhook "https://example.com/"

出力例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"createdDate": "2026-01-19T05:48:04.6116167+00:00",
"dailyRecurrence": {
"time": "1730"
},
"id": "/subscriptions/{SubscriptionId}/resourcegroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"location": "japaneast",
"name": "shutdown-computevm-{VMName}",
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"resourceGroup": "{ResourceGroupName}",
"status": "Enabled",
"targetResourceId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "UTC",
"type": "microsoft.devtestlab/schedules",
"uniqueIdentifier": "xxx"
}

コマンド実行例 (自動シャットダウン スケジュール削除)

1
az vm auto-shutdown -g {ResourceGroupName} -n {VMName} --off

出力例:

1
削除時は特に応答は返却されません。

コマンド実行例 (タイムゾーンを変更する)

上述のとおり、az vm auto-shutdown では任意のタイムゾーンが指定できず、UTC 固定となります。 この問題を回避するため、az resource update により、後から任意のタイムゾーンに変更することが可能です。以下はタイムゾーンを "(UTC+09:00) 大阪、札幌、東京" に変更する例です。

1
az resource update --ids "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}" --set properties.timeZoneID="Tokyo Standard Time"

出力例:

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
28
29
30
31
{
"extendedLocation": null,
"id": "/subscriptions/{SubscriptionId}/resourcegroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"identity": null,
"kind": null,
"location": "japaneast",
"managedBy": null,
"name": "shutdown-computevm-{VMName}",
"plan": null,
"properties": {
"createdDate": "2026-01-19T06:23:41.6245163+00:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Enabled",
"targetResourceId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"resourceGroup": "{ResourceGroupName}",
"sku": null,
"tags": null,
"type": "microsoft.devtestlab/schedules"
}

Azure PowerShell にて自動シャットダウンの設定を確認する方法

Get-AzResource にて自動シャットダウンの設定を確認できます。

コマンド実行例

1
2
3
4
5
# リソースの取得
$shutdownResource = Get-AzResource -ResourceId "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}"

# 設定の表示
$shutdownResource.Properties

出力例(自動シャットダウン リソースが存在し設定がオンの場合):

1
2
3
4
5
6
7
8
9
10
11
status               : Enabled
taskType : ComputeVmShutdownTask
dailyRecurrence : @{time=1730}
timeZoneId : Tokyo Standard Time
notificationSettings : @{status=Enabled; timeInMinutes=30; webhookUrl=https://example.com/; emailRecipient=foo@bar.com;
notificationLocale=ja}
createdDate : 2026/01/19 6:23:41
targetResourceId : /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsof
t.Compute/virtualMachines/{VMName}
provisioningState : Succeeded
uniqueIdentifier : xxx

出力例(自動シャットダウン リソースが存在しているが設定がオフの場合):

1
2
3
4
5
6
7
8
9
10
11
status               : Disabled
taskType : ComputeVmShutdownTask
dailyRecurrence : @{time=1730}
timeZoneId : Tokyo Standard Time
notificationSettings : @{status=Enabled; timeInMinutes=30; webhookUrl=https://example.com/; emailRecipient=foo@bar.com;
notificationLocale=ja}
createdDate : 2026/01/19 6:54:45
targetResourceId : /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsof
t.Compute/virtualMachines/{VMName}
provisioningState : Succeeded
uniqueIdentifier : xxx

出力例(自動シャットダウン リソースが存在しない場合):

1
2
3
4
Get-AzResource: The Resource 'microsoft.devtestlab/schedules/shutdown-computevm-{VMName}' under resource group '{VMName}' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
StatusCode: 404
ReasonPhrase: Not Found
OperationID : xxx

Azure PowerShell にて自動シャットダウンを設定する方法

Set-AzResource にて自動シャットダウンを設定できます。コマンド実行時に -Force パラメーターを指定することで、ユーザーの確認を求めずにコマンドを強制的に実行することも可能です。

コマンド実行例 (自動シャットダウン スケジュール作成)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Set-AzResource -ResourceId "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}" -Properties @{
status = "Enabled"
timeZoneId = "Tokyo Standard Time"
dailyRecurrence = @{
time = "1730"
}
notificationSettings = @{
status = "Enabled"
timeInMinutes = 30
notificationLocale = "ja"
webhookUrl="https://example.com/"
emailRecipient = "foo@bar.com"
}
taskType = "ComputeVmShutdownTask"
targetResourceId = "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}"
}

出力例:
-Force パラメーターの指定がない場合、リソースの更新可否について選択する必要があるため、更新してもよければそのまま Enter キーまたは Y キーを押下してリソースを更新します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Confirm
Are you sure you want to update the following resource:
/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/
shutdown-computevm-{VMName}
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):

Name : shutdown-computevm-{VMName}
ResourceId : /subscriptions/{SubscriptionId}/resourcegroups/{ResourceGroupName}/providers/microsoft.d
evtestlab/schedules/shutdown-computevm-{VMName}
ResourceName : shutdown-computevm-{VMName}
ResourceType : microsoft.devtestlab/schedules
ResourceGroupName : {ResourceGroupName}
Location : japaneast
SubscriptionId : {SubscriptionId}
Properties : @{status=Enabled; taskType=ComputeVmShutdownTask; dailyRecurrence=; timeZoneId=Tokyo Standard Time;
notificationSettings=; createdDate=2026-01-19T06:54:45.4836921+00:00; targetResourceId=/subscripti
ons/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virt
ualMachines/{VMName}; provisioningState=Succeeded; uniqueIdentifier=xxx}

コマンド実行例 (自動シャットダウン スケジュール削除)

Remove-AzResource にて自動シャットダウンの設定を削除できます。コマンド実行時に -Force パラメーターを指定することで、ユーザーの確認を求めずにコマンドを強制的に実行することも可能です。

1
Remove-AzResource -ResourceId "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}"

出力例:
-Force パラメーターの指定がない場合、リソースの削除可否について選択する必要があるため、削除してもよければそのまま Enter キーまたは Y キーを押下してリソースを削除します。

1
2
3
4
5
Confirm
Are you sure you want to delete the following resource:
/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
True

REST API にて自動シャットダウンの設定を確認する方法

Global Schedules - Get にて自動シャットダウンの設定を確認できます。

1
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-{VMName}?api-version=2018-09-15

コマンド実行例

curl や PowerShell の Invoke-RestMethod コマンドレットなどにおいても REST API の実行は可能ですが、Azure CLI コマンドである az rest を用いて REST API を実行することで、az login によりログインした資格情報を使用して自動的に認証を行うので、簡単に REST API を実行できます。

1
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-{VMName}?api-version=2018-09-15"

出力例(自動シャットダウン リソースが存在し設定がオンの場合):

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
{
"id": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"location": "japaneast",
"name": "shutdown-computevm-{VMName}",
"properties": {
"createdDate": "2026-01-19T06:54:45.4836921+00:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"notificationLocale": "ja",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Enabled",
"targetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"type": "microsoft.devtestlab/schedules"
}

出力例(自動シャットダウン リソースが存在しているが設定がオフの場合):

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
{
"id": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"location": "japaneast",
"name": "shutdown-computevm-{VMName}",
"properties": {
"createdDate": "2026-01-19T06:54:45.4836921+00:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"notificationLocale": "ja",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Disabled",
"targetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"type": "microsoft.devtestlab/schedules"
}

出力例(自動シャットダウン リソースが存在しない場合):

1
Not Found({"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.DevTestLab/schedules/shutdown-computevm-{VMName}' under resource group '{resourceGroupName}' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"}})

REST API にて自動シャットダウンを設定する方法

Global Schedules - Create Or Update にて自動シャットダウンを設定できます。

1
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{VMName}?api-version=2018-09-15

また、Global Schedules - Delete にて自動シャットダウンの設定を削除できます。

1
DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{VMName}?api-version=2018-09-15

コマンド実行例 (自動シャットダウン スケジュール作成)

1
2
3
4
5
6
7
8
9
10
11
# body を組み立てる
$body = "{'location':'japaneast','properties':{'status':'Enabled','taskType':'ComputeVmShutdownTask','timeZoneId':'Tokyo Standard Time','targetResourceId':'/subscriptions{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}','dailyRecurrence':{'time':'1730'},'notificationSettings':{'status':'Enabled','emailRecipient':'foo@bar.com','timeInMinutes':30,'webhookUrl':'https://example.com/','notificationLocale':'ja'}}}"

# Invoke request
$result = az rest `
--method put `
--url "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-{VMName}?api-version=2018-09-15" `
--body $body

# 整形して表示
$result | ConvertFrom-Json | ConvertTo-Json -Depth 10

出力例:

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
{
"id": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.devtestlab/schedules/shutdown-computevm-{VMName}",
"location": "japaneast",
"name": "shutdown-computevm-{VMName}",
"properties": {
"createdDate": "2026-01-19T17:17:45.1471113+09:00",
"dailyRecurrence": {
"time": "1730"
},
"notificationSettings": {
"emailRecipient": "foo@bar.com",
"notificationLocale": "ja",
"status": "Enabled",
"timeInMinutes": 30,
"webhookUrl": "https://example.com/"
},
"provisioningState": "Succeeded",
"status": "Enabled",
"targetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}",
"taskType": "ComputeVmShutdownTask",
"timeZoneId": "Tokyo Standard Time",
"uniqueIdentifier": "xxx"
},
"type": "microsoft.devtestlab/schedules"
}

コマンド実行例 (自動シャットダウン スケジュール削除)

1
2
3
az rest `
--method delete `
--url "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-{VMName}?api-version=2018-09-15"

出力例:

1
削除時は特に応答は返却されません。

最後に

今回は、Azure VM の自動シャットダウンについて、よくいただくご質問であるコマンドによる設定および確認方法についての情報をご紹介しました。
今後も自動シャットダウンのご利用にお役立ていただける情報を、どんどんご紹介していきたいと思いますので、どうぞよろしくお願いします!


本ブログの内容は弊社の公式見解として保証されるものではなく、開発・運用時の参考情報としてご活用いただくことを目的としています。もし公式な見解が必要な場合は、弊社ドキュメント (https://learn.microsoft.comhttps://support.microsoft.com) をご参照いただくか、もしくは私共サポートまでお問い合わせください。