記事の目的 (Overview)
Defender for Servers P2 をサブスクリプションレベルで有効化している環境において、特定の Azure VM / Arc-enabled Server を Defender for Servers 対象から除外する (課金対象外にする)方法 を解説します。
このガイドでは以下を利用します:
- GitHub 公開スクリプト ResourceLevelPricingAtScale.ps1 を用いた変更方法
https://github.com/Azure/Microsoft-Defender-for-Cloud/tree/main/Powershell%20scripts/Defender%20for%20Servers%20on%20resource%20level
対象読者:
- クラウドセキュリティアーキテクト
- Azure / Defender for Cloud 運用管理者
- コスト最適化を担当する FinOps / 運用チーム
前提条件 (Prerequisites)
1. Defender for Servers の有効化状態
- サブスクリプションで Defender for Servers P2 が有効化されていること。
2. RBAC 権限
次の権限のいずれかが必要です:
- Owner / Contributor(サブスクリプションまたは対象リソースグループ)
- Defender for Cloud の課金設定を変更できる Security Admin ロール
必要な操作:
- VM リソースのタグ変更
- Defender for Cloud API へのアクセス
3. 実行環境
- PowerShell 7.x または Windows PowerShell 5.1
- Azure PowerShell モジュール (Az.*)
- GitHub へアクセスできるインターネット接続
- (オフライン環境の場合)GitHub ZIP を事前にダウンロードし格納する
4. 利用するスクリプト
Microsoft 公式 GitHub:
- ResourceLevelPricingAtScale.ps1
5. 対象リソース
- Azure Virtual Machines
- Arc-enabled Servers
- Virtual Machine Scale Sets
設定作業
Azure VM / Arc-enabled Server を Defender for Servers P2 の課金対象から除外(Free 化)するために、以下の 4 ステップを順番に実施します。
- VM にタグの追加 (DefenderForServers:Disable)
- ResourceLevelPricingAtScale.ps1 スクリプトの実行
- VM から拡張機能のアンインストール
- Defener for Endpoint のオフボーディングスクリプト実行
それでは各設定をやってみましょう~
1. VM にタグの追加 (DefenderForServers:Disable)
対象 VM を Free(除外)として扱うための識別タグを付与します。
任意のタグを利用できますので、以下のタグ以外でも大丈夫です。
-
Tag Name:
DefenderForServers -
Tag Value:
Disable
Azure Portal 手順
- Azure Portal にサインイン
- 対象 VM をクリック
- Tags を開く
- 以下を入力:
- Name:
DefenderForServers - Value:
Disable
- Name:
- Save をクリックして保存
2. ResourceLevelPricingAtScale.ps1 スクリプトの実行
付与したタグを基に、対象 VM を Defender for Servers の Free プランに切り替えるスクリプトを実行します。
以下のコマンドでもスクリプトをダウンロードできます。
$scriptUrl = "https://raw.githubusercontent.com/Azure/Microsoft-Defender-for-Cloud/refs/heads/main/Powershell%20scripts/Defender%20for%20Servers%20on%20resource%20level/ResourceLevelPricingAtScale.ps1"
$outputPath = "ResourceLevelPricingAtScale.ps1"
Invoke-WebRequest -Uri $scriptUrl -OutFile $outputPath
Github から直接ダウンロードも可能です。
https://github.com/Azure/Microsoft-Defender-for-Cloud/blob/main/Powershell%20scripts/Defender%20for%20Servers%20on%20resource%20level/ResourceLevelPricingAtScale.ps1
ダウンロードしたスクリプトファイルを実行します。
以下のパラメーターの入力が必要です。
- サブスクリプション ID
- 設定したタグ名
- 設定したタグ値
- 設定する Defender for Servers の値 ('Free' or 'Standard' or 'Delete' or 'Read')
実行すると最初に サブスクリプション ID を入力します。
PS C:\temps > .\ResourceLevelPricingAtScale.ps1
Enter your SubscriptionId: 8c17e3ac-5866-4598-abcd-1234567890
次に仮想マシンに設定したタグを利用するため、TAG と入力します
Enter 'RG' to set pricing for all resourced under a given Resource Group, or 'TAG' to set pricing for all resources with a given tagName and tagValue: TAG
仮想マシンに設定したタグを入力します
Enter the name of the tag: DefenderForServers
Enter the value of the tag: Disable
タグが付与された仮想マシンなどの情報が表示されます。処理を続行する場合は何かキーを押します。
Found the following resources:
Virtual Machines:
1 : hubsql01
-------------------
Virtual Machine Scale Sets:
-------------------
ARC Machines:
-----------------------------------------------------------------------
Press any key to proceed or press 'N' to exit:
以下のパラメーターを利用できます。今回は Defender for Servers の対象から除外するため、Free を指定すると、実行結果も表示されます。
- Free: Defener for Servers から除外する
- Standard:Defener for Servers を有効にする
- Delete:Defender for Cloud から削除する
- Read:現在の設定情報を表示する
Enter the command set these resources - 'Free' or 'Standard' or 'Delete' or 'Read' (choosing 'Free' will remove the Defender protection; 'Standard' will enable the 'P1' subplan; 'Delete' will remove any explicitly set configuration (the resource will inherit the parent's configuration); 'Read' will read the current configuration):Free
-------------------
Processing (setting or reading) Virtual Machines:
Token expires on: 12/23/2025 17:40:35 - currentTime: 12/23/2025 17:16:25
Processing (setting or reading) pricing configuration for 'hubsql01':
Successfully updated pricing configuration for hubsql01
-------------------
Processing (setting or reading) Virtual Machine Scale Sets:
-------------------
Processing (setting or reading) ARC Machine:
-----------------------------------------------------------------------
-----------------------------------------------------------------------
Summary of Pricing API results:
-------------------
Found Virtual Machines count: 1
Successfully processed (set or read) Virtual Machines count: 1
Failed processing (setting or reading) Virtual Machines count: 0
Found Virtual Machine Scale Sets count: 0
Successfully processed (set or read) Virtual Machine Scale Sets result: 0
Failed processing (setting or reading) Virtual Machine Scale Sets count: 0
Found ARC machines count: 0
Successfully processed (set or read) ARC Machines count: 0
Failed processing (setting or reading) ARC Machines count: 0
-------------------
Overall
Successfully processed (set or read) resources: 1
Failures processing (setting or reading) resources: 0
なお、Read で実行すると、Defender for Servers の設定状況を確認できますので試してみてください。
Successfully read pricing configuration for hubsql01:
{
"id": "/subscriptions/8c17e3ac-5866-4598-abcd-1234567890/resourceGroups/rg-hub/providers/Microsoft.Compute/virtualMachines/hubsql01/providers/Microsoft.Security/pricings/VirtualMachines",
"name": "VirtualMachines",
"type": "Microsoft.Security/pricings",
"properties": {
"inherited": "False",
"pricingTier": "Free",
"freeTrialRemainingTime": "P30D"
}
}
これで、タグを設定した仮想マシンのみ Defender for Servers を Free プランに設定することができました。
3. VM から拡張機能のアンインストール
無料プランになった仮想マシンでは MDE.Windows 拡張機能は不要になるため、アンインストールします。

4. Defener for Endpoint のオフボーディングスクリプト実行
最後に Defender for Endpoint をオフボードします。Defender for Servers のプランを Free に変更しても、Defender for Endpoint は自動でオフボードされませんので、ご注意ください。
そのため、Defender ポータルにアクセスし対象 OS 向けのオフボードスクリプトをダウンロードします。
ダウンロードしたスクリプトを実行して、オフボード完了です。
PS C:\Temp\WindowsDefenderATPOffboardingPackage_valid_until_2024-11-22> .\WindowsDefenderATPOffboardingScript_valid_until_2025-12-30.cmd
オフボーディングされると WindowsDefenderAdvanced Threat Protection サービスが停止されますので、そこから確認するのがよさそうです。
Get-Service Sense
以上で作業は終了です。
まとめ
Defender for Servers の対象から特定 VM のみ除外する操作は、コスト最適化・検証環境管理・段階的導入など多くの実務シナリオで役立ちます。本記事の手順を活用することで、安全かつ確実に「個別 VM のみ Free 化」を実現できますので、ぜひお試しいただければと思います。
最近のランサムウェア被害がニュースになっていますので、Defender for Endpoint のような EDR 製品を利用することは非常に重要と思っています。
もし他製品の EPP との競合で無効化を検討している場合は、Defender for Endpoint を ブロックモードの EDR で利用することもご検討ください。
EPP である Defender Antivirus をパッシブモードに変更することで、すでに利用されている EPP をメインでアンチウイルスとして利用し、Defender for Endpoint のEDR 機能することができます。
Defender for Servers の無効化ではなく、EPP との共存でご利用いただくことでよりセキュアな環境を実現できればと思っています。
無効化した Defender for Servers を再び利用したい場合 (2026/1/5 追記)
ResourceLevelPricingAtScale.ps1 スクリプトは、リソース個別に Defender for Servers の設定を実行する機能が提供されています。
Defender for Servers P1 、P2 どちらのプランを有効化するか選択することが可能です。有効化するプランにより手順が少しことなりますので、設定後に有効化されたプランが意図したものになっているか確認することがおすすめです。
Defender for Servers P1 を有効化する
スクリプトを実行し、無効化した仮想マシンで Standard を設定すると、Defender for Servers P1 が有効になります。
- スクリプトで
Standardを設定
PS C:\temp\DfSP2> .\ResourceLevelPricingAtScale.ps1
Enter your SubscriptionId: 8c17e3ac-5866-4598-abcd-1234567890
Enter 'RG' to set pricing for all resourced under a given Resource Group, or 'TAG' to set pricing for all resources with a given tagName and tagValue: TAG
Enter the name of the tag: DefenderForServers
Enter the value of the tag: Disable
Found the following resources:
Virtual Machines:
1 : hubsql01
-------------------
Virtual Machine Scale Sets:
-------------------
ARC Machines:
-----------------------------------------------------------------------
Press any key to proceed or press 'N' to exit:
-------------------
Enter the command set these resources - 'Free' or 'Standard' or 'Delete' or 'Read' (choosing 'Free' will remove the Defender protection; 'Standard' will enable the 'P1' subplan; 'Delete' will remove any explicitly set configuration (the resource will inherit the parent's configuration); 'Read' will read the current configuration): Standard
-------------------
Processing (setting or reading) Virtual Machines:
Token expires on: 01/05/2026 22:40:31 - currentTime: 01/05/2026 21:26:48
Processing (setting or reading) pricing configuration for 'hubsql01':
Successfully updated pricing configuration for hubsql01
- 再度スクリプトを実行し、Read を実行して適用されるプランを確認
"id": "/subscriptions/8c17e3ac-5866-4598-abcd-1234567890/resourceGroups/rg-hub/providers/Microsoft.Compute/virtualMachines/hubsql01/providers/Microsoft.Security/pricings/VirtualMachines",
"name": "VirtualMachines",
"type": "Microsoft.Security/pricings",
"properties": {
"inherited": "False",
"extensions": [
{
"name": "MdeDesignatedSubscription",
"isEnabled": "False"
}
],
"enablementTime": "2026-01-05T12:26:49.2140878Z",
"subPlan": "P1",
"pricingTier": "Standard",
"freeTrialRemainingTime": "PT0S"
しばらくすると、MDE.Windows の拡張機能がインストールされ、MDE に自動オンボードされます。

Defender for Servers P2 を有効化する
Defender for Servers P2 を有効化したい場合、スクリプトで Delete を選択します。そうすると、仮想マシンの課金情報が削除され、サブスクリプションで有効化したプランが適用される動作になります。
注意
私の環境では、Defender for Servers P2 の再有効化されるまで 17 時間ほどかかりました。Delete 実行してもすぐに反映されない可能性があるためご注意ください。参考情報として、私の環境での実行時間です。
- Delete 実施: 2026/1/5 21:47
- MDE.Windows インストール:2026/1/6 14:34
- スクリプトで
Deleteを実施
Press any key to proceed or press 'N' to exit:
-------------------
Enter the command set these resources - 'Free' or 'Standard' or 'Delete' or 'Read' (choosing 'Free' will remove the Defender protection; 'Standard' will enable the 'P1' subplan; 'Delete' will remove any explicitly set configuration (the resource will inherit the parent's configuration); 'Read' will read the current configuration): Delete
-------------------
Processing (setting or reading) Virtual Machines:
Token expires on: 01/05/2026 22:40:31 - currentTime: 01/05/2026 21:47:24
Processing (setting or reading) pricing configuration for 'hubsql01':
Successfully deleted pricing configuration for hubsql01
- 再度スクリプトを実行し、Read を実行して適用されるプランを確認
Press any key to proceed or press 'N' to exit:
-------------------
Enter the command set these resources - 'Free' or 'Standard' or 'Delete' or 'Read' (choosing 'Free' will remove the Defender protection; 'Standard' will enable the 'P1' subplan; 'Delete' will remove any explicitly set configuration (the resource will inherit the parent's configuration); 'Read' will read the current configuration): Read
~~~ ログが長いため一部省略 ~~~
}
],
"subPlan": "P2",
"pricingTier": "Standard",
"freeTrialRemainingTime": "PT0S"
}
Standard を選択したときと同様に、しばらくすると MDE.Windows がインストールされ MDE に自動オンボードされます。

細かなユースケース
個々の仮想マシンで Defender for Servers の設定を変更する場合、サブスクリプションで Defender for Servers を有効にする必要がある などの条件に応じた設定が必要になります。
細かなユースケースは、以下の公開ドキュメントに紹介されていますので、利用している環境に応じてプランの変更を実施する際に参考にしていただければと思います。
https://learn.microsoft.com/ja-jp/azure/defender-for-cloud/plan-defender-for-servers-select-plan#decide-on-deployment-scope
今回実施したシナリオは以下の2つです。
| ユースケース | サブスクリプションで有効になっている | 詳細 | 方法 |
|---|---|---|---|
| 個々のマシンに対してプラン 1 を有効にする | はい | サブスクリプションで Defender for Servers プラン 2 が有効になっているときは、API を使用して、サブスクリプション内の個々のマシンに対してプラン 2 ではなく、プラン 1 を有効にできます。 | Azure Microsoft Security の価格操作グループを使用します。 価格の更新で、PUT 要求を使用して pricingTier プロパティを Standard に設定し、サブプランを P1 に変更します。pricingTier プロパティは、選択したスコープでプランが有効になっているかどうかを示します。 |
| 個々のマシンのプラン構成を削除する | はい / いいえ | サブスクリプション全体の設定を有効にするには、マシンから構成を削除します。 | 価格の更新で、Delete 要求を使用して構成を削除します。 |



