> 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.md).

# Azure Automation への接続

RealmJoin PowerShell モジュールを使用して Azure Automation Account を RealmJoin Portal に接続し、RealmJoin が Tenant 内で runbook を展開、実行、監視できるようにします。

## 概要

RealmJoin ポータルが提供できるようにするには [runbook](https://docs.realmjoin.com/ja/zi-dong-hua/runbooks.md) 日常タスクを自動化するには、次のものを接続する必要があります。 [Azure Automation](https://learn.microsoft.com/en-us/azure/automation/overview) アカウント。これは runbook のホストとして機能し、 [アクセス許可](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md) runbook が環境内で動作するために必要です。

Automation Account は次の設定で構成されます。 [RealmJoin PowerShell module](https://docs.realmjoin.com/ja/zhan-kai/onboarding-realmjoin-portal/advanced-setup.md)。ポータルが、すぐにコピーできるコマンドを生成します。作成するアプリ登録も、管理するクライアント シークレットもありません。

{% hint style="info" %}
お使いの Tenant では、従来の **RealmJoin Runbook Management** アプリ登録で runbooks がすでに構成されていますか？ その場合は、次を参照してください [RealmJoin 管理アプリへの切り替え](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/managed-app-migration.md)。Automation Account と runbooks はそのまま維持され、Tenant ごとのクライアント シークレットは削除されます。
{% endhint %}

## 考慮事項

Automation Account の [Managed Identity](https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview) には広範な [アクセス許可](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md) 環境内で、たとえば Entra ID のグループやユーザー オブジェクトを変更したり、Exchange Online でメールボックスを管理したりする能力が必要です。これらの権限の悪用を防ぐため、このアカウントへの管理アクセスは制限してください。

既存の Automation Account を使用する場合、RealmJoin ポータルは次のものから取得した runbook を自動的に作成、更新、削除することに注意してください。 [runbook の共有オンライン リポジトリ](https://github.com/realmjoin/realmjoin-runbooks)。この機能は既存の Automation Account ではサポートされない場合があります。確信が持てない場合は、RealmJoin runbooks 用に専用の Azure Automation Account を作成することを推奨します。これはセットアップ コマンドが行います。

## セットアップがデプロイするもの

セットアップ コマンドを実行すると、次が作成されます:

* 次の **RealmJoin Azure Resources** あなたの Entra ID テナント内の service principal（まだ存在しない場合）
* セッション内に **Automation Account** リソース グループのリージョンにシステム割り当てのマネージド ID を付与したもの、または指定した場合は既存の Automation Account
* **Contributor** RealmJoin の Service Principal に対して、その Automation Account にスコープされたもの。これにより RealmJoin は runbook を同期して開始できます
* 次の **アプリケーション権限** モジュールに含まれるマネージド ID 用のもの — Microsoft Graph、Office 365 Exchange Online、Windows Defender ATP、SharePoint Online

RealmJoin は独自のマルチテナント アプリケーションを使用して Azure に対して認証します。お使いの Tenant にはアプリ登録もクライアント シークレットも作成されず、RealmJoin はその Automation Account の外部ではいかなる権限も取得しません。

{% hint style="warning" %}
マネージド ID の **Entra ID ディレクトリ ロール** — Intune Administrator、Exchange Administrator、User Administrator など — は **は** セットアップ コマンドによって割り当てられます。ただし、これらは別途付与する必要があります。次を参照してください [ロールと権限の付与](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md#granting-roles-and-permissions)。これらがないと、共有 runbooks の大部分は動作しません。
{% endhint %}

## 前提条件

### RealmJoin Portal で

* Settings 領域へのアクセス権を付与するロール（`CanReadSettingsDetails`、参照: [利用可能な権限](https://docs.realmjoin.com/ja/to/permission/custom-roles/available-permissions.md)）。設定ページは、短時間有効なオンボーディング トークンを含むセットアップ コマンドを生成します。

### Azure で

* Azure サブスクリプションと 1 つの **既存のリソース グループ** デプロイ先 — モジュールはリソース グループを作成しません。Automation Account 用に別個のリソース グループを用意することを推奨します。
* 必要に応じて既存の Automation Account。指定しない場合はアカウントが作成されます。

### PowerShell を実行しているマシン上で

* **PowerShell 5.1** 以降（Windows PowerShell または PowerShell 7）
* へのアクセス [PowerShell Gallery](https://www.powershellgallery.com/packages/RealmJoin) RealmJoin module をインストールするための
* 次の `Az.Accounts`, `Az.Resources` と `Az.Automation` モジュール — RealmJoin module が現在のユーザー向けに固定バージョンで自動的にインストールします

### サインインに使用するアカウントの権限

* **Microsoft Entra ID:** Service Principal を作成する権限 **およびアプリケーション権限を付与する権限** — セットアップは、Managed Identity に Graph、Exchange、Defender、および SharePoint のアプリ ロールを割り当てます。実際には、これは次を意味します *Global Administrator* または *特権ロール管理者*.
* **Azure サブスクリプション:** リソース グループにデプロイする権限 **と** そこでロール割り当てを作成するための権限。たとえば *Owner*、または *Contributor* と *User Access Administrator* / *Role Based Access Control Administrator*.
* サインインは `Connect-AzAccount` を通じて行われます。これは **Azure PowerShell**  のファーストパーティ アプリケーションを使用します。ユーザー同意を制限しているテナントでは、最初にそのアプリケーションへの管理者同意を付与する必要がある場合があります。

{% hint style="warning" %}
コマンドを次の環境で実行してください: **新しく開いたローカルの** PowerShell セッションで、 **Azure Cloud Shell**は避けてください。RealmJoin module には、 `Az.*` モジュール。別のバージョンがセッションにすでに読み込まれている場合 — 通常は Cloud Shell でそうなります — モジュールはバージョン競合で停止し、新しいセッションを開かない限り解決できません。
{% endhint %}

## セットアップ

{% stepper %}
{% step %}

#### リソース グループを準備する

Azure Portal で、Automation Account を格納するリソース グループを作成するか選択します。その名前と、それが存在するサブスクリプションの ID を控えておきます。

次を使用したい場合は **既存の** Automation Account についても、その名前を控えておきます。
{% endstep %}

{% step %}

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

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

このページでは、runbook の構成が RealmJoin PowerShell モジュールを介して管理されることが示され、コマンド ブロックが表示されます。次を使用してください **Copy** ボタンを使ってコピーしてください。

```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 -Token "<Token>" 6>&1
```

{% hint style="info" %}
**について `6>&1`:** これらのコマンドは、PowerShell の Information ストリームに進捗を出力します。 `6>&1` リダイレクトによってその出力がコンソールに表示されます。これがないと進捗メッセージは表示されません。
{% endhint %}
{% endstep %}

{% step %}

#### 対象パラメータを追加する

`Set-RJAutomationAccount` デプロイ先を知る必要があります。実行する前に最後の行を完成させてください:

```powershell
Set-RJAutomationAccount -ResourceGroupName "rg-realmjoin" -SubscriptionId "<SubscriptionId>" -Token "<Token>" 6>&1
```

* `-ResourceGroupName` は必須です。省略すると、PowerShell が入力を求めます。
* `-SubscriptionId` は省略可能です — 指定しない場合は、現在の Azure コンテキストのサブスクリプションが使用され、複数ある場合は選択を求められます。
* `-AutomationAccountName` は省略可能です。新しい Automation Account の名前を指定するか、既存の **既存の** アカウントを使用するために渡します。そうしない場合は、生成された名前で新しいものが作成されます。

{% hint style="warning" %}
このコマンドを既存の Automation Account に向けると、RealmJoin が想定する設定も適用されます。システム割り当てのマネージド ID、Basic SKU、および public network access です。アカウントを再利用する前に、これが要件に合っているか確認してください。
{% endhint %}
{% endstep %}

{% step %}

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

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

次の方法でサインインするよう求められます `Connect-AzAccount`。アカウントに複数のテナントまたはサブスクリプションへのアクセス権がある場合、モジュールが選択を求めます。

デプロイは、Service Principal、Automation Account、権限の 3 つの手順で実行され、作成される各リソースが報告されます。1 回の実行には通常数分かかります。

{% hint style="info" %}
まず何が起こるか見たいですか？ `-WhatIf`  に追加すると、Azure Resource Manager の What-If プレビューが表示されます。なお、サインインと `Az` モジュールのインストールは引き続き行われます。プレビューにはその両方が必要だからです。
{% endhint %}

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

{% step %}

#### マネージド ID に Entra ID ロールを割り当てる

セットアップはマネージド ID にアプリケーション権限を付与しますが、Entra ID ディレクトリ ロールは付与しません。今すぐそれらを割り当ててください — 次を参照してください [ロールと権限の付与](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md#granting-roles-and-permissions) 最新の一覧と、それを実行するスクリプトについて。

マネージド ID のオブジェクト ID は、Azure Portal の Automation Account の Account Settings > Identity に表示されます。

<figure><img src="https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2F4ecZSM3NW9PWJJlaNmR4%2Fimage.png?alt=media&amp;token=e5d5b56b-50f3-4f35-a41b-7cb4230dd3f3" alt=""><figcaption><p>Automation Account のマネージド ID</p></figcaption></figure>
{% endstep %}

{% step %}

#### ポータルで確認して、最初の同期を開始します

に戻り **設定 → Runbooks** 、 **Refresh**。RealmJoin が新しい構成を取得し、初回の runbook インポートを開始します。同期が完了するまでページを開いたままにしてください。

サブスクリプション、リソース グループ、Automation Account 名、および場所は、次の下に読み取り専用で表示されます **Azure 接続** — 以後は PowerShell モジュールによって管理されます。
{% endstep %}
{% endstepper %}

## ポータルで管理する設定

次の 2 つの設定は、 **設定 → Runbooks** セットアップ後も

* **ブランチ** — 次のブランチ [共有 runbook リポジトリ](https://github.com/realmjoin/realmjoin-runbooks) を追跡したいものです。セットアップではこれが次に設定されます `production`。特別な理由がない限り、これが適切な選択です。
* **Hybrid Runbook Worker の同期を有効にする** および使用するワーカー グループについては、次を参照してください [Hybrid Runbook Worker](https://docs.realmjoin.com/ja/zi-dong-hua/runbooks/hybrid-runbook-worker.md)。このグループは、ここで選択できるようになる前に Automation Account に登録されている必要があります。

どちらかを保存すると、runbook 同期がトリガーされます。

後で構成または権限の問題が発生した場合は、 **cmdlet を表示** Azure 接続の下にあるボタンでコマンドを再表示できます。再実行しても安全で、不足しているものだけが適用されます。

## 従来のセットアップ（Tenant ごとのアプリ登録）

{% hint style="warning" %}
以下のセットアップでは、 **RealmJoin Runbook Management** お使いの Tenant にクライアント シークレット付きのアプリ登録を作成します。これは、過去にこの方法で構成された Tenant の参照用としてのみ文書化されています。新しい構成には使用しないでください — 次に従ってください [セットアップ](#setup) 上記、または [既存の構成を管理アプリに切り替える](https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation/managed-app-migration.md).
{% endhint %}

<details>

<summary>旧式のセットアップを表示する</summary>

この方法では、Automation Account は Azure Portal で手動作成され、その権限は 2 つの外部スクリプトで割り当てられ、RealmJoin は Tenant ごとのアプリ登録とクライアント シークレットで認証していました。

**パート 1 — Azure Automation Account を作成する**

1. 次へ移動します [Azure Portal > Automation Accounts](https://portal.azure.com/#create/Microsoft.AutomationAccount) に移動し、新しい Automation Account を作成します。
2. ［基本］タブで、サブスクリプション、リソース グループ、Automation Account 名、リージョンを選択します。
3. ［詳細］タブで、System Assigned Managed Identity が有効になっていることを確認します。
4. ［レビュー + 作成］を選択して、Automation Account を作成します。
5. Automation Account を含むリソース グループに移動し、［IAM］タブで Automation Account に Contributor を割り当てます。

![Automation Account の作成](https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2FqjBLc2zH3XCCqfAViEsU%2Fimage.png?alt=media\&token=257816e0-eb8a-478c-973f-fb288324d8c8)

![system assigned managed identity を有効にする](https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2FM9N3OxNzrzQXFxSaKIpP%2Fimage.png?alt=media\&token=1e7c4d5b-d604-415b-89e0-4816a7f04a26)

**パート 2 — Automation Account に権限を割り当てる**

マネージド ID の権限は Azure Portal では付与できません。The [approle-and-directoryrole-granter](https://github.com/Workplace-Foundation/approle-and-directoryrole-granter) スクリプトは、次に公開されている JSON ファイルからアプリ権限と Entra ID ロールの両方を割り当てます [runbooks リポジトリ](https://github.com/realmjoin/realmjoin-runbooks/tree/production/docs/other/json):

```powershell
. .\GrantAppPermToEntApp.ps1 -enterpriseAppObjId "<ManagedIdentityObjectId>" -permissionsTemplate .\AllRealmJoinRunbooks_collected_permissions.json
. .\AssignAzureADRoleToEntApp.ps1 -objectId "<ManagedIdentityObjectId>" -rolesTemplate .\AllRealmJoinRunbooks_collected_rbacroles.json
```

**パート 3 — RealmJoin の Service Principal を作成する**

ポータルの［Settings > Runbooks］で、最初に Tenant ID、Subscription ID、および Resource Group が入力されました。その後、このページに実行用の Azure CLI スニペットが表示され、次を作成しました **RealmJoin Runbook Management** リソース グループに対する Contributor 権限を持つアプリ登録:

```
az provider register --namespace Microsoft.Automation
az ad sp create-for-rbac -n "RealmJoin Runbook Management" --role contributor --scopes /subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroup>
```

**パート 4 — ウィザードを完了する**

ポータルに戻ると、 `appId` と `password` その出力のものは、Automation Account 名、共有 runbook リポジトリのブランチ（`production`）および Automation Account の場所とともに入力されました。保存すると、初回の runbook インポートが開始されました。

![RealmJoin ポータルでの Automation Account 接続](https://3438325150-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2FA0X3M2c9d13pxVt87Pf8%2Fimage.png?alt=media\&token=8e2f2b18-c3b1-4704-8cc8-eb4d43297dd1)

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