# Windows Defender実行ジョブガイド

<figure><img src="https://762006384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJXOXEifAmpyvNVL1to%2Fuploads%2FPGxOZ3JN1yZonO5U9tsd%2FReference%20-%20Windows%20Defender%20Running%20Job%20Guide.png?alt=media&#x26;token=3ecaaf23-a4d8-471f-992c-26ea66aa8654" alt=""><figcaption></figcaption></figure>

本ページでは、Windows Defenderウイルス対策サービス (**WinDefend**) が実行中かどうかを確認し、停止していれば起動する**ジョブ**を紹介します。このジョブは**JobUpdate**ポリシーでエンドポイントに配備します。

**対象:** WindowsにKeeper特権マネージャーを配備するIT管理者。

### ジョブの動作 <a href="#what-the-job-does" id="what-the-job-does"></a>

* **WinDefend**サービス (Windows Defenderウイルス対策サービス) の状態を**確認**します。
* **サービスが停止している場合、** `Start-Service -Name WinDefend` で起動します。
* **すでに実行中の場合**、何もせず正常終了します。
* **スケジュール** (既定: 60分ごと) および**起動時**に**実行**されるため、Defenderを定期的に確認し、停止されていれば復旧できます。

ジョブは**Service**コンテキストでPowerShellタスクを1つだけ使います。エージェントは通常LOCAL SYSTEMで動作し、WinDefendサービスを起動できます。

### 要件 <a href="#prerequisites" id="prerequisites"></a>

* **Windows**にKeeper特権マネージャーエージェントがインストールされ、実行されていること。
* `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` にPowerShellがあること。
* **JobUpdate**ポリシーの作成と**Process Configuration Policies**の実行ができること (例: Keeper管理コンソールから)。

### ジョブ定義 (JSON全文) <a href="#job-definition-full-json" id="job-definition-full-json"></a>

次のジョブJSONをJobUpdateポリシー (**Extension.JobJson**) に指定するか、ファイルで配備する場合は `Jobs/ensure-windows-defender-running.json` として保存します。

```
{
  "id": "ensure-windows-defender-running",
  "name": "Ensure Windows Defender is running",
  "description": "Checks if the Windows Defender Antivirus service (WinDefend) is running; if not, starts it. Deploy via JobUpdate policy. Runs on schedule (default every 60 min) and on Startup.",
  "enabled": true,
  "asUser": false,
  "priority": 5,
  "schedule": {
    "intervalMinutes": 60
  },
  "events": [
    { "eventType": "Startup" }
  ],
  "parameters": [],
  "tasks": [
    {
      "id": "check-and-start-defender",
      "name": "Check Windows Defender service and start if stopped",
      "ExecutionType": "Service",
      "command": "powershell.exe",
      "executablePath": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
      "arguments": "-NoProfile -ExecutionPolicy Bypass -Command \"& { $s = Get-Service -Name WinDefend -ErrorAction SilentlyContinue; if (-not $s) { exit 1 }; if ($s.Status -ne 'Running') { Start-Service -Name WinDefend -ErrorAction Stop }; exit 0 }\"",
      "expectedExitCode": 0,
      "timeoutSeconds": 30,
      "continueOnFailure": false
    }
  ],
  "mqttTopics": { "allowedPublications": ["KeeperLogger"], "allowedSubscriptions": [] },
  "osFilter": { "windows": true, "linux": false, "macOS": false }
}
```

***

### JobUpdateポリシーでジョブを配備する <a href="#deploy-the-job-via-jobupdate-policy" id="deploy-the-job-via-jobupdate-policy"></a>

1. ポリシーストアまたはKeeper管理コンソールで**JobUpdateポリシーを作成**し、次を設定します。
   * **PolicyType:** `JobUpdate`
   * **Status:** `enabled`
   * **Extension:**
     * **JobId:** `ensure-windows-defender-running`
     * **Action:** `Add`
     * **JobJson:** 上記のジョブオブジェクト全文 (1行でも整形済みでも可)。
2. **ポリシー構成の例:**

   ```
   {
     "PolicyId": "deploy-ensure-windows-defender-running",
     "PolicyName": "Deploy job: Ensure Windows Defender is running",
     "PolicyType": "JobUpdate",
     "Status": "enabled",
     "Extension": {
       "JobId": "ensure-windows-defender-running",
       "Action": "Add",
       "JobJson": {
         "id": "ensure-windows-defender-running",
         "name": "Ensure Windows Defender is running",
         "description": "Checks if the Windows Defender Antivirus service (WinDefend) is running; if not, starts it.",
         "enabled": true,
         "asUser": false,
         "priority": 5,
         "schedule": { "intervalMinutes": 60 },
         "events": [{ "eventType": "Startup" }],
         "parameters": [],
         "tasks": [
           {
             "id": "check-and-start-defender",
             "name": "Check Windows Defender service and start if stopped",
             "ExecutionType": "Service",
             "command": "powershell.exe",
             "executablePath": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
             "arguments": "-NoProfile -ExecutionPolicy Bypass -Command \"& { $s = Get-Service -Name WinDefend -ErrorAction SilentlyContinue; if (-not $s) { exit 1 }; if ($s.Status -ne 'Running') { Start-Service -Name WinDefend -ErrorAction Stop }; exit 0 }\"",
             "expectedExitCode": 0,
             "timeoutSeconds": 30,
             "continueOnFailure": false
           }
         ],
         "mqttTopics": { "allowedPublications": ["KeeperLogger"], "allowedSubscriptions": [] },
         "osFilter": { "windows": true, "linux": false, "macOS": false }
       }
     }
   }
   ```
3. ポリシーを目的のWindowsコレクションまたはマシンに**割り当て**ます。
4. エージェントがジョブを受け取れるよう**Process Configuration Policies**を**実行**します。
   * 通常のスケジュール (例: ポリシー同期後) に任せる、または
   * 手動でトリガー: `POST https://127.0.0.1:6889/api/Jobs/process-configuration-policies/run` (管理者認証)
5. **ジョブが存在するか確認:**\
   `GET https://127.0.0.1:6889/api/Jobs` — `ensure-windows-defender-running` が表示されるはずです。

### ジョブの実行タイミング <a href="#when-the-job-runs" id="when-the-job-runs"></a>

* **起動時 (Startup)** — エージェント (またはマシン) 起動時に1回実行されます。
* **60分ごと** — `schedule.intervalMinutes` に従います。間隔を変える場合はジョブJSONの `intervalMinutes` を変更します。

手動トリガーは不要です。オンデマンドで1回だけ実行したい場合は (例: `POST .../api/Jobs/ensure-windows-defender-running/run`) を利用します。

### 検証 <a href="#verification" id="verification"></a>

* **サービス状態 (PowerShell):**

  ```
  Get-Service -Name WinDefend
  ```

  `Get-Service` の結果で、状態 (Status) が `Running` (実行中) であることを確認します。
* **エージェントログ:** タスク `check-and-start-defender` およびPowerShellやサービス関連のエラーを確認します。
* **ジョブを1回実行する (任意):**

  ```
  Invoke-RestMethod -Method Post -Uri "https://127.0.0.1:6889/api/Jobs/ensure-windows-defender-running/run" -SkipCertificateCheck
  ```

### トラブルシューティング <a href="#troubleshooting" id="troubleshooting"></a>

| 現象                              | 確認すること                                                                                                                                                      |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| エンドポイントにジョブがない                  | JobUpdateポリシーが割り当てられているか。Process Configuration Policiesが実行済みか。`GET /api/Jobs` にジョブが出るか。                                                                     |
| 終了コード1                          | WinDefendサービスが存在しない可能性 (例: エディションが異なる)。マシン上で `Get-Service WinDefend` を確認。                                                                                   |
| サービス起動でアクセス拒否                   | エージェントがサービスを起動できるアカウント (例: LOCAL SYSTEM) で動いているか。                                                                                                           |
| Start-Serviceが失敗する (例: 状態が「無効」) | サービスの開始種別が**自動**または**手動**である必要があります。**無効**の場合はStart-Serviceは失敗します。管理者権限のプロンプトで `Set-Service -Name WinDefend -StartupType Automatic` を実行するか、services.mscで設定。 |
| 間隔が意図と異なる                       | ポリシー内の**JobJson**を編集し、`schedule.intervalMinutes` を変更 (例: 30)。再度Process Configuration Policiesを実行するか、JobUpdateの**Action**を**Update**にして修正済みジョブ全文で更新。         |

### 参考情報 <a href="#reference" id="reference"></a>

* **ジョブID:** `ensure-windows-defender-running`
* **ジョブファイル (ポリシーを使わない場合):** `Jobs/ensure-windows-defender-running.json`
* **サービス名:** `WinDefend` (Windows Defenderウイルス対策サービス)
* **対象プラットフォーム:** Windowsのみ。

ジョブとポリシーの概要については、ジョブとアプリケーション (はじめに) をご参照ください。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/endpoint-privilege-manager/user-guides/windows-defender-running-job-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
