> For the complete documentation index, see [llms.txt](https://docs.realmjoin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/managed-app-migration.md).

# RealmJoin 管理アプリへの切り替え

RealmJoin PowerShell モジュールを使用して、Tenant ごとの RealmJoin Runbook Management アプリ登録とそのクライアント シークレットを、RealmJoin 管理のマルチテナント アプリに置き換えます。

## 概要

PowerShell ベースのオンボーディング前に Azure Automation に接続していたテナントは、 **RealmJoin Runbook Management** 自分の Tenant 内のアプリ登録です。RealmJoin は、そのアプリのクライアント ID とクライアント シークレットを使って、Automation Account に対して認証します。

新たにオンボードされたテナントでは、もはやこれを行いません。RealmJoin は独自の **マルチテナント アプリケーション**で、Automation Account には Contributor が付与されるだけで、それ以外はありません。既存の構成は次を使って切り替えられます。 [RealmJoin PowerShell module](https://docs.realmjoin.com/ja/zhan-kai/onboarding-realmjoin-portal/advanced-setup.md).

{% hint style="info" %}
マネージド アプリへの切り替えを推奨します。現時点ではレガシー構成も引き続きサポートされていますが、将来的に変更される可能性があり、影響を受けるお客様には別途お知らせします。
{% endhint %}

### 切り替える理由

* **ローテーションすべきクライアント シークレットがありません。** テナントごとのシークレットは期限切れになり、更新が必要です。期限切れになると、誰かが気づくまで runbook の同期と実行が停止します。マネージド アプリには、そちら側のシークレットはありません。
* **管理するアプリ登録はありません** あなたの Tenant 内で。
* **より狭いスコープ。** レガシーの service principal には通常、リソース グループ全体に Contributor が付与されていました。マネージド アプリに付与される Contributor は Automation Account のみです。
* Automation Account（名前とリソース グループ）、そのオブジェクト ID を持つシステム割り当ての managed identity、そこに割り当てられた Entra ID のロールとアプリ権限、およびインポート済みの runbook は保持されます。

## 切り替えで変わること

同じもの `Set-RJAutomationAccount` 新規セットアップ時と同じコマンドを使用し、対象はあなたの **既存の** Automation Account です。これにより、

* 次を作成します **RealmJoin Azure Resources** まだ存在しない場合は、あなたの Tenant 内に service principal を作成します
* それに次を付与します **Contributor** その Automation Account に対して
* モジュールに同梱されているセットに対して、managed identity のアプリケーション権限 — Microsoft Graph、Exchange Online、Defender、SharePoint — を再適用します
* 今後は managed app を使って認証するよう RealmJoin に指示します

Automation Account の名前、managed identity、および object ID はそのまま保持されるため、Entra ID のロールや割り当てたすべての権限は有効なままです。runbook は一から再インポートされません。

{% hint style="warning" %}
この登録により、構成済みの **ブランチ** 共有 runbook リポジトリの `production`。テナントが意図的に別のブランチを使用している場合は、後で Portal の Settings → Runbooks で再設定してください。
{% endhint %}

## 前提条件

新規セットアップの場合と同じです — 次を参照してください [前提条件](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation.md#prerequisites) オンボーディング ページで。要するに:

* コマンドとそのトークンを取得するための RealmJoin Portal の Settings 領域へのアクセス
* PowerShell 5.1 以降。新しく開いたローカル セッションで — **は** Azure Cloud Shell
* Entra ID で service principal を作成し、アプリケーション権限を付与できるアカウント（*Global Administrator* または *特権ロール管理者*）およびサブスクリプション内でロール割り当てを作成できるアカウント（*Owner*、または *Contributor* 加えて *User Access Administrator*)

## 移行

{% stepper %}
{% step %}

#### RealmJoin Portal からコマンドをコピーする

RealmJoin ポータルで、次へ移動します **設定 → Runbooks** (<https://portal.realmjoin.com/settings/runbooks-configuration>).

ページには次の通知が表示されます **「RealmJoin managed app に切り替える」** と、すぐにコピーできるコマンド ブロックが表示されます。 **Copy** ボタンを使ってコピーしてください。

<figure><img src="https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2Fgit-blob-84baa16d78a6621d669669725722fb774e6aa0ee%2Fmanaged-app-migration-notice.png?alt=media" alt="Settings → Runbooks with the notice &#x22;Switch to the RealmJoin managed app&#x22; and the pre-filled Set-RJAutomationAccount command"><figcaption><p>Settings → Runbooks の移行通知とコマンド</p></figcaption></figure>

コマンドには、現在のリソース グループ、Automation Account 名、およびサブスクリプションがあらかじめ入力されています:

```powershell
$latest = [version](Find-Module RealmJoin -Repository PSGallery -ErrorAction Stop).Version
if (-not (Get-Module -ListAvailable RealmJoin | Where-Object Version -ge $latest)) {
    Install-Module RealmJoin -Force -AllowClobber -ErrorAction Stop
}
Import-Module RealmJoin -Force
Set-RJAutomationAccount -ResourceGroupName "<ResourceGroup>" -AutomationAccountName "<AutomationAccountName>" -SubscriptionId "<SubscriptionId>" -Token "<Token>" 6>&1
```

{% hint style="warning" %}
を使用して結果を RealmJoin に登録します。 `-AutomationAccountName` が含まれており、あなたの **既存の** アカウントを指定します。これがないと、モジュールは使用中のものを切り替える代わりに、新しい空の Automation Account を作成します。
{% endhint %}
{% endstep %}

{% step %}

#### コマンドを実行する

ブロックを新しい PowerShell セッションに貼り付けて実行してください。トークンの有効期限はおよそ1時間です。期限切れの場合は、設定ページを再読み込みしてコマンドをもう一度コピーしてください。

次の方法でサインインするよう求められます `Connect-AzAccount`。その後、デプロイでは適用されるたびに各リソースとロール割り当てが報告され、既に存在するものは検出されてスキップされます。

{% hint style="info" %}
**その後のサインアウト:** Azure へのサインインは、コマンド完了後もアクティブなままです。終わったら `Disconnect-AzAccount`  を実行して、既存のセッションからサインアウトしてください。
{% endhint %}
{% endstep %}

{% step %}

#### Portal で確認する

に戻り **設定 → Runbooks** 、 **Refresh**.

移行通知はなくなり、ページには次が表示されます **Runbook 同期設定** ブランチと Hybrid Runbook Worker のオプション、および読み取り専用の **Azure 接続** セクションです。Client ID と client secret は、もはや構成の一部ではありません。

<figure><img src="https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2Fgit-blob-06c1123395052f67c34b525ad9254d0cb2ca2990%2Fmanaged-app-migration-verified.png?alt=media" alt="Settings → Runbooks after the switch, with Runbook sync settings and the read-only Azure connection section"><figcaption><p>切り替え後の Runbook 構成</p></figcaption></figure>

ブランチが希望どおりであることを確認し、その後 runbook を実行して、実行が引き続き機能することを確認してください。
{% endstep %}

{% step %}

#### 古いアプリ登録をクリーンアップする

すべてが動作したら、 **RealmJoin Runbook Management** アプリ登録は runbook で使われなくなるため、リソース グループ上の Contributor ロール割り当てとともに Entra ID から削除できます。

{% hint style="warning" %}
まず、そのアプリ登録をほかに何が使用しているか確認してください。これは、レガシーの [Log Analytics](https://docs.realmjoin.com/ja/torogu/log-analytics.md) セットアップが再利用する可能性がある同じアプリです。そこでまだ Data Collector API を使用している場合、またはその移行前に書き込まれたログ データをまだ読み取っている場合は、アプリ登録とそのシークレットが引き続き必要です。次を参照してください [Log Ingestion API への移行](https://docs.realmjoin.com/ja/torogu/log-ingestion-api-migration.md).
{% endhint %}
{% endstep %}
{% endstepper %}

## トラブルシューティング

<details>

<summary>「RealmJoin module is outdated - execution cannot proceed」</summary>

すべての cmdlet は、セッションごとに 1 回、最新の公開バージョンを実行しているかを確認します。現在のバージョンをインストールしたら、セッションを閉じて新しいセッションを開いてください:

```powershell
Install-Module -Name RealmJoin -Force -Scope CurrentUser
```

</details>

<details>

<summary>module のバージョン競合が報告される</summary>

セッション内に `Az.*`  RealmJoin module が固定するものとは別のバージョンの module がすでに読み込まれています。これは実行中のセッション内では修正できません — PowerShell を閉じ、新しいセッションを開いてコマンドを再実行してください。これも Azure Cloud Shell を使わない理由です。

</details>

<details>

<summary>ロール割り当ての作成中に展開が失敗する</summary>

Automation Account 上で Contributor の割り当てを作成するには、アクセスを管理できるロールが必要です。たとえば *Owner*, *User Access Administrator* または *Role Based Access Control Administrator*. *Contributor* だけでは不十分です。

すでに存在するロール割り当ては検出されてスキップされるため、権限を修正した後にコマンドを再実行しても安全です。

</details>

<details>

<summary>アプリケーション権限の割り当て中にデプロイが失敗します</summary>

managed identity に Graph、Exchange、Defender、SharePoint のアプリ ロールを付与するには *Global Administrator* または *特権ロール管理者*。そのロールを持つ人にコマンドを実行してもらうか、ロールが有効になってからご自身で再度実行してください。

</details>

<details>

<summary>切り替え後に runbook の同期が動作しなくなる</summary>

開く **設定 → Runbooks** ページ上部に表示される警告を確認してください — RealmJoin は、ページが読み込まれるたびに Automation Account の構成を検証します。その後、 **cmdlet を表示** Azure connection の下でセットアップ コマンドを再実行してください。これは冪等で、不足しているものを再適用します。

</details>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/managed-app-migration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
