> 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/remote-actions-in-finder-classic/example-of-self-help-scenario-in-finder-classic.md).

# Finder（クラシック）での自己支援シナリオの例

{% hint style="info" %}
Nexthink FinderはWindows専用のデスクトップアプリケーションであり、その機能は現在Nexthink webインターフェース内で利用できます。 Nexthinkを直接ブラウザから使用できるようになり、ほとんどの機能で追加のデスクトップアプリケーションを必要としなくなりました。
{% endhint %}

現在ハードドライブのストレージ容量は非常に大きいですが、それでも有限です。 デバイスの毎日の使用により、ハードドライブは有用なドキュメントやプログラムだけでなく、多くの一時ファイル、ダウンロード、画像、およびその他の項目でますますディスクスペースを消費します。 これらの無駄なファイルが多くなると、新しいドキュメント、アプリケーション、および更新のための空きスペースがどんどん減少します。 デバイスでの自由なディスクスペースの量がある閾値を下回ると、そのデバイスは何も保存できなくなり、使用不能になります。

この例では、Nexthink Remote ActionsとNexthink Campaignsを活用して、デバイスでの空きディスクスペースが少ない状態を従業員に警告し、遅すぎる前にそれを解決するためのガイドを提供し、不要なファイルを削除してディスクスペースを解放するプロセスを学びます。

## Campaigns の作成 <a href="#exampleofself-helpscenarioinfinder-classic-creatingthecampaigns" id="exampleofself-helpscenarioinfinder-classic-creatingthecampaigns"></a>

従業員に特定の問題を警告し、その解決に導くためには、セルフヘルプシナリオにはCampaignsの使用が必要です。 Remote actionsは、キャンペーンの開始を制御し、従業員からの回答を受け取ることができます。 Remote actionsを通じてキャンペーンを推進するためには、次のことができます:

* 特定の問題を従業員に通知します。
* Suggest a series of steps (possibly with different options) to resolve the issue.
* 問題が解決され次第、ユーザーに通知します。

上記のアクションを実行するには、セルフヘルプシナリオには通常、2つのCampaignsが必要です。 我々の低ディスク空き容量の例では、以下の2つのCampaignsを作成します：

* **ディスククリーンアップの提案**は、従業員に空きディスクスペースが不足していることを警告し、次のいずれかを提案します：
  * ディスクの軽いクリーンアップ。
  * ディスクの深いクリーンアップ。
  * ディスクをクリーンアップしない場合、次のオプションがあります：
    * 後で再度尋ねます。
    * 二度と聞かないでください。
* **ディスククリーンアップ完了を確認してください**。このキャンペーンは、前回のキャンペーンでディスククリーンアップを拒否しなかった限り、クリーンアッププロセスの終了時にユーザーに通知します。

**ディスククリーンアップ提案**キャンペーンは、ディスククリーンアップを起こさない第三の選択肢を提供します。 この選択肢は、後でディスクをクリーンアップすることを決める可能性がある従業員や、警告にもかかわらずディスクをクリーンアップしない、またはリモートアクションの助けを借りずに自分でディスクをクリーンアップする従業員に適しています。

このキャンペーンがリモートアクションから開始されることを示すには、エディターの**RECIPIENTS**セクションで文を完全にして、**リモートアクションとともに**オプションを選択します。 これがFinderのキャンペーンエディターでの**ディスククリーンアップ提案**キャンペーンの表示です。

<figure><img src="/files/tLAICRSgH92oUH8StXkX" alt="" width="340"><figcaption></figcaption></figure>

そして、これは**ディスククリーンアップ完了を確認**するキャンペーンの表示です。

<figure><img src="/files/wqsWEhc2XXyIeMfjAp4X" alt="" width="340"><figcaption></figcaption></figure>

## リモートアクションの作成 <a href="#exampleofself-helpscenarioinfinder-classic-creatingtheremoteaction" id="exampleofself-helpscenarioinfinder-classic-creatingtheremoteaction"></a>

低い空きディスクスペースを修正するために、私たちの例のリモートアクションには以下が含まれます：

* システムドライブの空きスペースが少ないデバイスを選択する調査。
* 最初のキャンペーン**ディスククリーンアップ提案**の質問に対する社員の回答を集計し、それに基づいてデバイスのディスクをクリーンアップするかどうかを決定するスクリプト。

### ターゲット調査の定義 <a href="#exampleofself-helpscenarioinfinder-classic-definingthetargetinvestigation" id="exampleofself-helpscenarioinfinder-classic-definingthetargetinvestigation"></a>

リモートアクションを作成する前に、システムドライブに5 GB以下の空きディスクスペースがあるデバイスを返す調査を作成します。 この調査は、ディスクをクリーンアップする提案を拒否したデバイスのオーナーをフィルターアウトします。 スタンドアローンキャンペーンとは異なり、リモートアクションから開始されたキャンペーンの回答は**Device**オブジェクトのフィールドとして探します。**User**オブジェクトではありません。

<figure><img src="/files/6ZC9cg4klHcxBtve4VhJ" alt="" width="442"><figcaption></figcaption></figure>

## リモートアクションのスケジューリング <a href="#exampleofself-helpscenarioinfinder-classic-schedulingtheremoteaction" id="exampleofself-helpscenarioinfinder-classic-schedulingtheremoteaction"></a>

[リモートアクションを作成する](/platform/ja/user-guide/remote-actions/remote-actions-in-finder-classic/creating-a-remote-action-with-finder-classic.md)と、それに先の調査をリンクします。 リモートアクションのエディターで：

1. リモートアクションを自動的に実行するオプションをチェックします。
2. 調査をドラッグアンドドロップして、**SCHEDULE**セクションの適切なエリアに配置します。

<figure><img src="/files/yZACnpnxvMrmS9sLNQqM" alt="" width="340"><figcaption></figcaption></figure>

評価期間として、リモートアクションはより応答性を高めるために10分ごとに調査を実行します。 負荷を減らすために、評価期間を1時間に設定することも十分です。

トリガー期間として、リモートアクションは1日を指定します。 この方法で、デバイスが引き続き低空きディスクスペースの問題を抱えている場合は、リモートアクションは短期間で同じユーザーを煩わせることなく、代わりに次の日まで待ちます。

## PowerShellスクリプトの追加 <a href="#exampleofself-helpscenarioinfinder-classic-addingthepowershellscript" id="exampleofself-helpscenarioinfinder-classic-addingthepowershellscript"></a>

お好みのテキストエディターで、修復スクリプトを入力します。 ファイルを保存する際、スクリプトのテキストをUTF-8 with BOMでエンコードすることを忘れないでください。 これを怠ると、リモートアクションがトリガーされた際にターゲットデバイスでスクリプトが実行されなくなります。

このスクリプトは以下を実行します：

1. 関連するキャンペーンの識別子（Uid）を保持するために文字列型の2つのパラメーターを定義します。
2. **Add-Type**コマンドレットを使用して、リモートアクションを扱うNexthink ダイナミックライブラリ（`nxtremoteactions.dll`）を追加します。
3. **Add-Type**コマンドレットを使用して、リモートアクションから開始されたキャンペーンを扱うNexthink ダイナミックライブラリ（`nxtcampaignaction.dll`）を追加します。 このライブラリにはキャンペーンの開始と回答取得を処理するためのオブジェクト`[Nxt.CampaignAction]`が含まれています。
4. [エラー処理用の trap](https://github.com/nexthink/documentation.online-product-documentation/blob/develop/ja_docs/user-guide/remote-actions/getting-started-with-remote-actions/creating-remote-actions/writing-scripts-for-remote-actions-on-windows.md#writingscriptsforremoteactionsonwindows-errorhandling) を定義します。
5. 最初のキャンペーンの質問へのユーザーの回答を取得し、それに応じた処理を行うための**HandleFullResponse**関数を定義します：ディスクをクリーンアップするか、否定的な回答を処理する。 キャンペーンの回答の実際の値を取得するための関数`[Nxt.CampaignAction]::GetResponseAnswer`の使用に注意してください。
6. リサイクルビン内のすべてのファイルを削除する**CleanupDisk**関数を定義します（cmdlet **Clear-RecycleBin**はPowerShell 5.0以降でのみ利用可能であることに注意してください）。 簡単のため、この例のスクリプトは軽いクリーンアップと深いクリーンアップを区別しませんが、関数にはタイプを引数として受け付けます。 情報提供のみのCampaignなので回答を集める必要はありません。 これはスタンドアローンとして開始されるため、単なる情報提供のキャンペーンであり、収集する回答はありません。
7. **GetRecycleBinSize**のヘルパー関数を定義して、リサイクルビン内のすべてのファイルの合計サイズを取得し、クリーンアップされたスペースの量を出力としてEngineに報告します。
8. ディスクをクリーンアップしてほしくないユーザーに対し、単にアクションを延期するか、もう二度と聞かれないようにしたいかを質問する**HandleNegativeResponse**関数を定義します。
9. ユーザーの応答と消去されたバイト数（あれば）をEngineに返す**WriteOutputs**ヘルパー関数を定義します。
10. 最初のキャンペーンを実行して、ユーザーにディスクのクリーンアップを提案します。 最初のキャンペーンのUidと120秒のタイムアウトを使用して、`[Nxt.CampaignAction]::RunCampaign`関数の使用に注意してください。
11. `[Nxt.CampaignAction]::GetResponseStatus`関数を使用して応答ステータスを取得します。
12. 応答の状態に基づいて：
    * ユーザーが最初のキャンペーンの質問に完全に回答した場合、**HandleFullResponse**関数を呼び出します。
    * キャンペーンを延期し、ユーザーが延期を回答した場合、またはキャンペーンがタイムアウトした場合、この状態をEngineに返します。
    * ユーザーがディスクをクリーンアップする提案を拒否した場合、キャンペーンを拒否し、この状態をEngineに返します。

```
#
# リサイクルビンをクリーンアップ
# バージョン 1.0.0.0
# 著作権 © 2017 Nexthink SA, Switzerland
#

param(
    [string]$ProposeCampaignId,
    [string]$ConfirmCampaignId
)

Add-Type -Path $env:NEXTHINK\RemoteActions\nxtremoteactions.dll
Add-Type -Path $env:NEXTHINK\RemoteActions\nxtcampaignaction.dll

trap {
    $host.ui.WriteErrorLine($_.ToString())
    exit 1
}

function HandleFullResponse($response) {
    $responseAnswer = [Nxt.CampaignAction]::GetResponseAnswer($response, "Clean disk")[0]
 switch($responseAnswer) {
 "Light" { CleanupDisk($responseAnswer) }
 "Deep"  { CleanupDisk($responseAnswer) } 
 "No"    { HandleNegativeResponse($response) }
 default { throw "Invalid answer, please ensure the first question name is set to 'Clean disk'" }    
    }
}

function CleanupDisk($type) {
    $path="$($env:SystemDrive)\`$recycle.bin"
    $bytesCleaned = GetRecycleBinSize($path)
        Clear-RecycleBin -Force -ErrorAction SilentlyContinue
    WriteOutputs $type $bytesCleaned
    [Nxt.CampaignAction]::RunStandAloneCampaign($ConfirmCampaignId)
}

function GetRecycleBinSize($path) {
    $measure=0
    Try {
        $measure=(Get-ChildItem $path -force -recurse -ErrorAction SilentlyContinue) | measure length -sum
    }
    Catch {
    }   
 return $measure.sum
}

function HandleNegativeResponse($response) {
    $responseAnswer = [Nxt.CampaignAction]::GetResponseAnswer($response, "Ask again") 
 switch($responseAnswer) {
 "Postponed" { WriteOutputs("Postponed") }
 "Declined"  { WriteOutputs("Declined") }
 default     { throw "Invalid answer, please ensure the second question name is set to 'Ask again'" }
    }
}

function WriteOutputs($userReply, $bytesCleaned){
    [Nxt]::WriteOutputString("UserReply", $userReply)
    [Nxt]::WriteOutputSize("SpaceCleaned", $bytesCleaned)
}

$response = [Nxt.CampaignAction]::RunCampaign($ProposeCampaignId, 120)
$responseStatus = [Nxt.CampaignAction]::GetResponseStatus($response)
switch($responseStatus) {
 "fully"     { HandleFullResponse($response) }
 "timeout"   { WriteOutputs("Postponed") }
 "postponed" { WriteOutputs("Postponed") }
 "declined"  { WriteOutputs("Declined") }
 default  { throw "Failed to handle campaign response: " + $responseStatus }
}
```

セキュリティの理由から、Nexthinkはスクリプトに署名することを推奨します。 テスト目的であれば、事前生産環境でのみ署名されていないスクリプトを安全に使用することができます。

リモートアクションのエディターで、**インポート...をクリックしてスクリプトをリモートアクションにリンクします。 Finderはスクリプトのソースを解釈し、スクリプトの下に検出されたパラメーターと出力の両方を一覧表示します。 スクリプトのパラメーター**は以前に作成された2つのキャンペーンのUidsであり、**出力**はユーザーの応答とクリーンアップされたディスク空き容量のサイズです。

キャンペーンのUidをリモートアクションに渡すには：

1. Finderの左側のメニューで、**Campaigns**セクションを選択します。
2. 目的のキャンペーンを右クリックします。
3. メニューから**エクスポート > キャンペーン Uidをクリップボードにコピー**を選択します。
4. Finderの左側のメニューで、**Remote actions**セクションを選択します。
5. キャンペーンを立ち上げるリモートアクションの名前をダブルクリックして、リモートアクションのエディターを開きます。
6. スクリプトのテキストの下にある**パラメーター**セクションで、スクリプト内のキャンペーンのUidを保持する文字列パラメーターに対応するテキスト入力ボックスを右クリックします。
7. 望みのキャンペーンのUidを挿入するには、**貼り付け**を選択します。

## 高度な設定 <a href="#exampleofself-helpscenarioinfinder-classic-advancedconfiguration" id="exampleofself-helpscenarioinfinder-classic-advancedconfiguration"></a>

リモートアクションが管理者権限を必要としないため、スクリプトを**現在のインタラクティブユーザー**として実行するオプションをチェックします。 管理者権限を必要とするリモートアクションは、代わりに**ローカルシステム**アカウントとして実行されなければなりません。

ユーザーがキャンペーンに回答し、スクリプトがタイムアウトする前に終了できるように十分な時間を割り当てます。 この例では、300秒（5分）のタイムアウト値を定義します。


---

# 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/remote-actions-in-finder-classic/example-of-self-help-scenario-in-finder-classic.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.
