> 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 に接続した Tenant は、1つの **RealmJoin Runbook Management** 自分の Tenant 内のアプリ登録です。RealmJoin は、そのアプリのクライアント ID とクライアント シークレットを使用して、あなたの Automation Account に対して認証します。

新たにオンボードされた Tenant では、もはやこれを行いません。RealmJoin は独自の **マルチテナント アプリケーション**、あなたの Automation Account に Contributor が付与されるだけで、それ以外はありません。既存の構成は、 [RealmJoin PowerShell モジュール](/ja/zhan-kai/onboarding-realmjoin-portal/advanced-setup.md).

{% hint style="info" %}
managed app への切り替えを推奨します。現在は従来の構成も引き続きサポートされていますが、将来的に変更される可能性があり、影響を受けるお客様には別途通知されます。
{% endhint %}

### 切り替える理由

* **ローテーションする client secret がありません。** Tenant ごとのシークレットは期限切れになり、更新が必要です。期限が切れると、誰かが気付くまで runbook の同期と runbook の実行が停止します。managed app は、あなた側にシークレットを持ちません。
* **管理するアプリ登録はありません** あなたの Tenant 内で。
* **より限定されたスコープ。** 従来の Service Principal には通常、リソース グループ全体に Contributor が付与されていました。managed app に付与されるのは Automation Account のみに対する Contributor です。
* Automation Account（名前とリソース グループ）、その object 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`にリセットします。あなたの Tenant が意図的に別のブランチを使用している場合は、後で Portal の Settings → Runbooks で再設定してください。
{% endhint %}

## 前提条件

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

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

## 移行

{% stepper %}
{% step %}

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

RealmJoin Portal で次へ移動します **Settings → Runbooks** (<https://portal.realmjoin.com/settings/runbooks-configuration>).

ページには次の通知が表示されます **「RealmJoin managed app に切り替える」** コピー可能なコマンド ブロックとともに表示されます。 **コピー** ボタンでコピーします。

<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" %}
確認してください `-AutomationAccountName` が含まれており、あなたの **既存の** アカウント名を指定していることを。これがないと、モジュールは使用中のものを切り替えるのではなく、新しい空の Automation Account を作成します。
{% endhint %}
{% endstep %}

{% step %}

#### コマンドを実行します

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

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

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

{% step %}

#### Portal で確認する

次に戻り **Settings → Runbooks** を選択し **更新**.

移行通知は消え、ページには次が表示されます **Runbook 同期設定** ブランチと Hybrid Runbook Worker オプションに加え、読み取り専用の **Azure connection** セクションが表示されます。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** app registration は runbook では使用されなくなるため、リソース グループ上の Contributor ロール割り当てとともに Entra ID から削除できます。

{% hint style="warning" %}
まず、その app registration を他に使っているものがないか確認してください。これは、従来の [Log Analytics](/ja/torogu/log-analytics.md) setup が再利用するのと同じアプリです。そこでまだ Data Collector API を使用している、またはその移行前に書き込まれたログ データをまだ読み取っている場合は、app registration とその secret が引き続き必要です。次を参照してください [Log Ingestion API への移行](/ja/torogu/log-ingestion-api-migration.md).
{% endhint %}
{% endstep %}
{% endstepper %}

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

<details>

<summary>「RealmJoin module が古いです - 実行を続行できません」</summary>

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

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

</details>

<details>

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

ある `Az.*` RealmJoin module が固定しているものとは異なるバージョンの Az.\* 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* または *Privileged Role Administrator*。そのロールを持つ人にコマンドを実行してもらうか、ロールが有効化された後に自分で再度実行してください。

</details>

<details>

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

開き **Settings → Runbooks** ページ上部に表示される警告を確認してください。RealmJoin はページ読み込み時に Automation Account の構成を検証します。次に **Show cmdlet** Azure connection の下にある setup コマンドを再実行してください。これは冪等であり、不足しているものがあれば再適用します。

</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.
