> For the complete documentation index, see [llms.txt](https://docs.nexthink.com/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexthink.com/platform/ja/user-guide/remote-actions/setting-up-and-managing-remote-actions/creating-remote-actions/running-remote-actions-as-a-service-on-server-devices-windows-only.md).

# サーバーデバイス上でサービスとしてリモートアクションを実行する（Windows のみ）

リモートアクションでサービスと対話するために特定の Windows 資格情報が必要な場合、Nexthink には、特別に設定されたサービスのコンテキスト内で実行できる専用機能が用意されています。

Nexthink Library には、この機能を活用する以下のリモートアクションが含まれています：

* Active Directory グループへのユーザーの追加/削除。
* Active Directory グループへのデバイスの追加/削除。

これらのリモートアクションは、さまざまなユースケースのワークフローで使用されます。

サービスとして実行されるリモートアクションは、オンプレミスサーバーと安全に対話するための踏み台デバイスである Windows Server デバイスで使用するように設計されています。 サービスリモートアクションを設定および運用する前に、Windows サービスデバイスで追加のセットアップ作業を実行する必要があります。

リモートアクションの機密性を考慮し、Nexthink ではその使用を制限するために Nexthink の機能を活用することを推奨します：

* リモートアクションを実行できることが許可されたユーザーがいる場合にのみ、そのユーザーと選択的に共有します。
* 踏み台サーバー専用のエンティティを設定し、このデバイスでリモートアクションを実行できるロールを制限します。

{% hint style="warning" %}
サービスとして実行されるリモートアクションは、サードパーティシステム上でアクションを実行することに重点を置いており、リモートアクションの出力はサポートしていません。 実行時には、ステータスとステータスの詳細のみがプラットフォームに返送されます。
{% endhint %}

## ターゲット Windows Server のセットアップ <a href="#runningremoteactionsasaserviceonserverdevices-windowsonly-settingupthetargetwindowsserver" id="runningremoteactionsasaserviceonserverdevices-windowsonly-settingupthetargetwindowsserver"></a>

### 要件 <a href="#runningremoteactionsasaserviceonserverdevices-windowsonly-requirements" id="runningremoteactionsasaserviceonserverdevices-windowsonly-requirements"></a>

Nexthink では Windows Server 2019 の使用を推奨しています。

標準プロセスを使用して、デバイスに Nexthink Collector（バージョン 24.5 以降）を展開および設定します。

サービス内でスクリプトを実行するために使用する、通常はサービスアカウントであるユーザーアカウントを作成します：

1. 計画したリモートアクションを正常に実行するために必要な権限がアカウントにあることを確認します。 そのサービスアカウントには可能な限り最小限の権限のみを付与し、セキュリティのベストプラクティスを適用してください。 ベストプラクティスの例：
   1. [最小権限の管理モデルの実装](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-practices/implementing-least-privilege-administrative-models)
   2. [OU オブジェクトを使用した管理の委任](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/delegating-administration-by-using-ou-objects)
   3. [委任されたマネージド サービス アカウントの使用](https://learn.microsoft.com/en-us/windows-server/security/delegated-managed-service-accounts/delegated-managed-service-accounts-overview)
2. 該当する場合は、必要な PowerShell モジュールがインストールされていることを確認します。 たとえば、Nexthink Library のリモートアクションで ActiveDirectory と対話するには、PowerShell で次のコマンドラインを使用して ActiveDirectory モジュールをインストールする必要があります。\
   `Install-WindowsFeature RSAT-AD-PowerShell`
3. ログが保存される以下のフォルダーに対する書き込み権限がアカウントにあることを確認します。\
   `c:\ProgramData\Nexthink\Logs\User\`\
   `c:\ProgramData\Nexthink\RemoteActions\Scripts\Service`
4. 以下のフォルダーから PowerShell スクリプトを実行する権限がアカウントにあることを確認します。\
   `c:\ProgramData\Nexthink\RemoteActions\Scripts\Service`
5. ローカルセキュリティポリシーに基づき、アカウントがマシンで**サービスとしてログオン**できることを確認します。 ローカルユーザーの場合は、ローカル コンピューター ポリシー マネージャーで次の手順を実行します。*コンピューターの構成 > Windows の設定 > セキュリティの設定 > ローカル ポリシー > ユーザー権利の割り当て* に移動し、ユーザーまたはそのユーザーが所属するグループが **サービスとしてログオン** ポリシーに含まれていることを確認します。<br>

   <figure><img src="/files/fnNHH3rrB6yti2zSete3" alt="image-20240404-130808.png" width="534"><figcaption></figcaption></figure>

### サーバーで実行できるリモートアクションを制限する

サーバーのセキュリティをさらに強化し、不要なリモートアクションの実行を防ぐため、Nexthink ではサーバー上で実行するよう設計されたリモートアクション専用のカスタムコード署名証明書を使用することを推奨します。

サーバーデバイスで実行できるスクリプトを制限するには、次の手順を実行します：

* 踏み台デバイスでの実行を許可するリモートアクション専用に使用するコード署名証明書を取得します。
* サーバー上でのみ実行する必要がある各リモートアクション（例: AD グループへのユーザー/デバイスの追加/削除）について、専用のコード署名証明書を使用してリモートアクションスクリプトに署名（または再署名）し、署名済みスクリプトをリモートアクション設定にアップロードします。
* 使用予定のコード署名証明書を、サーバー上にのみ *ローカル コンピューター > 信頼された発行元* 証明書ストアへ展開し、信頼された発行元ストアに他のコード署名証明書が展開されていないことを確認します。 詳細については、[Windows でのリモートアクション用スクリプトの作成](/platform/ja/user-guide/remote-actions/setting-up-and-managing-remote-actions/creating-remote-actions/writing-scripts-for-remote-actions-on-windows.md)ドキュメンテーションを参照してください。
* リモートアクションの Collector 実行ポリシーを、デフォルト値（trusted\_or\_nexthink）ではなく **trusted** に設定します

コード証明書の取得、スクリプトへの署名、および証明書の展開方法の詳細については、[Windows でのリモートアクション用スクリプトの作成](/platform/ja/user-guide/remote-actions/setting-up-and-managing-remote-actions/creating-remote-actions/writing-scripts-for-remote-actions-on-windows.md)ドキュメンテーションを参照してください。

### サービスのインストール、作成、実行 <a href="#runningremoteactionsasaserviceonserverdevices-windowsonly-install-createandruntheservice" id="runningremoteactionsasaserviceonserverdevices-windowsonly-install-createandruntheservice"></a>

リモートアクションの実行に使用するサービスを設定するには、次の手順に従います：

1. **サービスを登録します**。 ローカル管理者として、次のコマンドを実行します。\
   `sc create "nxtcod_service" binpath= "\"C:\Program Files\Nexthink\Collector\Coordinator\nxtcod.exe\" --service-name \"nxtcod_service\" --queue-size 512 --max-concurrent-script-executions 4" DisplayName= "Nexthink RA Execution as a Service" start= auto`\
   `sc description "nxtcod_service" "Run Nexthink remote actions in a dedicated service account context"`

   **注記**：

   1. パラメーター `--service-name` は必須であり、リモートアクションの設定時にはその値 `nxtcod_service` を使用する必要があります。 Nexthink では、サービス自体と同じ値を使用することを推奨します。 値には英字、数字、および `_` のみを使用でき、最大 50 文字です。 この引数を指定しない場合、または無効な値を指定した場合は、サービスを開始できません。
   2. サービスでは、受け入れる負荷を制御するために、追加のパラメーター `--queue-size` および `--max-concurrent-script-executions` がサポートされています。 詳細については以下のセクションを参照してください。
2. **サービス設定を完了します**。 管理コンソールを使用する場合：
   1. **サービス**管理コンソール `services.msc` を開きます。
   2. ステップ 1 で作成したサービス `Nexthink RA Execution as a Service` を見つけてダブルクリックし、そのプロパティを編集します。
   3. **ログオン** タブで、アカウント名とそのパスワードを入力して、サービスで使用するアカウントを設定します。 このアカウントには、使用予定のリモートアクションスクリプトに必要な操作を実行するための権限が必要です。

      <figure><img src="/files/GSqASE42EwVc1ETSR7XD" alt="image-20240405-075205.png" width="404"><figcaption></figcaption></figure>
   4. **回復** タブで、障害発生時にサービスが再起動するよう回復オプションを設定します。 Nexthink では、次のパラメーターを使用して、障害が発生するたびにサービスを再起動することを推奨します：

      <figure><img src="/files/aHxqehwINk4bFuOSUqnA" alt="image-20240405-075125.png" width="402"><figcaption></figcaption></figure>
3. **サービスを開始します:** サービスの **全般** タブで **開始** をクリックするか、ローカル管理者として次のコマンドを実行します。\
   `sc start "nxtcod_service"`

### 異なるユーザーを使用するための追加サービスインスタンスの実行

同じデバイスで異なる資格情報を使用してリモートアクションを実行できるように、追加のサービスインスタンスを作成します。

追加のサービスを設定するには、次の変更を加えて上記と同じ手順に従います：

1. 最初のサービスで使用したものと似たコマンドラインを使用して追加のサービスインスタンスを作成しますが、異なるサービス名と表示名を使用します。 コマンドラインパラメーターを適宜調整します。\
   `sc create "nxtcod_service_bis" binpath= "\"C:\Program Files\Nexthink\Collector\Coordinator\nxtcod.exe\" --service-name \"nxtcod_service_bis\" --queue-size 512 --max-concurrent-script-executions 4" DisplayName= "Nexthink RA Execution as a Service (2)" start= auto`\
   `sc description "nxtcod_service_bis" "Run Nexthink remote actions in a dedicated service account context (2)"`
2. 前述の手順を使用してサービスを設定し、開始します。

### サービスの更新とアンインストール

Collector を更新すると、サービス実行可能ファイルも更新されます。 Collector の更新後にサービスを再起動し、最新バージョンが使用されていることを確認します。

Collector をアンインストールする前に、サービスのすべてのインスタンスを停止します。 これを行わないと、アンインストールプロセス中にエラーが発生します。

### 予想される負荷の監視 <a href="#runningremoteactionsasaserviceonserverdevices-windowsonly-monitoringtheexpectedload" id="runningremoteactionsasaserviceonserverdevices-windowsonly-monitoringtheexpectedload"></a>

一般的なワークフローのシナリオでは、同じサーバーが必要な各ユーザーまたはデバイスを処理するために多数のリモートアクションを処理します。 サーバーはリクエストをキューに入れ、指定された数のスレッドを並列で動作させながら順次処理します。

踏み台サーバーで想定されるリモートアクション実行スループットに合わせるには、コマンドラインパラメーターを使用して次の項目を設定します：

* **キューの長さ**: パラメーター `--queue-size`、デフォルト: 128、推奨: 1024、最大: 100000。
* サービス内で実行される**並列リモートアクション**の数: パラメーター `--max-concurrent-script-executions`、デフォルト: 2、推奨: 4、推奨される最大値: サーバーのコア数。

Nexthink Collector によって収集されたデータを活用し、制限を超えないようにします。

* サーバーの平均 CPU 使用率とメモリ使用量を確認し、リソースが枯渇していないことを検証します：

  ```
  device_performance.events past 24h
  | where device.name == "<proxy-device-name>"
  | summarize avg_cpu_usage = cpu_usage.avg() / number_of_logical_processors.avg(), avg_free_memory = free_memory.avg() by 1h
  | where avg_cpu_usage >= 80 or avg_free_memory <= 1GB
  ```
* 次の NQL クエリを実行して、リモートアクションの実行が失敗またはタイムアウトしていないことを確認します：

  ```
  remote_action.executions past 7d
  | where remote_action.name in ["<service-remote-action-names>"]
  | summarize total_executions = count(), in_progress = countif(status == in_progress), expired = countif(status == expired), success = countif(status == success), failure = countif(status == failure) by 1d, device.name
  ```

  * **進行中**の数が最大キューサイズを超えている場合は、`--queue-size` パラメーターの値を増やすことを検討してください。
  * **期限切れ**の数が増加している場合は、`--max-concurrent-script-executions` パラメーターの値を増やすことを検討してください。

## エラーのトラブルシューティング <a href="#runningremoteactionsasaserviceonserverdevices-windowsonly-troubleshootingerrors" id="runningremoteactionsasaserviceonserverdevices-windowsonly-troubleshootingerrors"></a>

| 症状                                                              | トラブルシューティング                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| サービス開始時のエラー: ローカル コンピューター上の `<ServiceName>` サービスが開始された後、停止しました。 | <p>Windows イベントログで該当するエラーメッセージを確認します。</p><p>一般的な原因は、必須のコマンドライン引数 <code>--service-name</code> が指定されていないことです。 問題を確認して修正するには、次の手順を実行します。</p><ul><li><strong>サービス</strong>管理コンソールからサービスを編集します。</li><li><strong>実行ファイルのパス</strong>の値にコマンドライン <code>--service-name "somevalue"</code> が正しく含まれていること、および <code>somevalue</code> が英字、数字、または <code>\_</code> のみで構成され、長さが 50 文字以下であることを確認します。</li><li>実行ファイルおよびそのパラメーターを変更するには、ローカル管理者として次のコマンドを実行し、コマンドライン引数を変更します。<br><code>sc config "nxtcod\_service" binpath= ""C:\Program Files\Nexthink\Collector\Coordinator\nxtcod.exe" --service-name "service\_1" --queue-size 512 --max-concurrent-script-executions 4"</code>。</li></ul> |
| リモートアクション実行時のエラー: サービスが見つかりません。                                 | <p>リモートアクションの <strong>スクリプト</strong> タブで設定したサービス名の値（例：<code>service\_1</code>）が、サービス用に設定した <code>--service-name</code> 引数の値と一致することを確認します。</p><ul><li><strong>サービス</strong>管理コンソールからサービスを編集します。</li><li><strong>実行ファイルのパス</strong>の値に、リモートアクション設定で使用した値と一致する引数 <code>--service-name "service\_1"</code> があることを確認します。</li><li>コマンドラインを変更するには、上記と同じ手順に従います。</li></ul>                                                                                                                                                                                                                                                                                                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.nexthink.com/platform/ja/user-guide/remote-actions/setting-up-and-managing-remote-actions/creating-remote-actions/running-remote-actions-as-a-service-on-server-devices-windows-only.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
