> 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 への接続

## 概要

{% embed url="<https://www.youtube.com/watch?v=Ijp9XnE8UuA>" %}

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

## 考慮事項

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

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

## 前提条件

* グローバル管理者権限
* 次の内容を含む PowerShell へのアクセス： [Az](https://learn.microsoft.com/en-us/powershell/azure/?view=azps-15.3.0) モジュールまたは [AZ CLI](https://learn.microsoft.com/en-us/cli/azure/?view=azure-cli-latest)
* Azure サブスクリプションでの Contributor 権限
* [runbook 要件](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md)

## 手順

{% stepper %}
{% step %}

#### Azure Automation Account を作成する

1. 次へ移動します： [Azure Portal > Automation Accounts](https://portal.azure.com/#create/Microsoft.AutomationAccount)
2. 新しい Automation Account を作成する
3. ［基本］タブで、希望する Subscription、Resource Group、Automation Account 名、および Region を選択します<br>

   <figure><img src="/files/558807d9e5dc3ff69a1f10e95dd9467cea3711ee" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Automation Account 用に別の Resource Group を用意することを推奨します
{% endhint %}

4. ［詳細設定］タブで、System Assigned Managed Identity が有効になっていることを確認します

   <figure><img src="/files/cebce7ea795223f29dc5b7c19035707ae50ca89f" alt=""><figcaption></figcaption></figure>
5. ［確認と作成］を選択し、Automation Account を作成します
6. Azure Automation Account を含む Resource Group に移動します
7. ［IAM］タブで、Azure Automation Account に Contributor 権限を割り当てます
   {% endstep %}

{% step %}

#### Azure Automation Account に権限を割り当てる

RealmJoin の共有 runbook は、Azure Automation のシステム割り当て Managed Identity を使用して、Entra ID、MS Graph API などと連携します。

Managed Identity の権限は現在、Azure Portal から付与できません。これらの権限を割り当てるには Microsoft Graph または PowerShell を使用してください。

1. 以下の PowerShell スクリプトと JSON ファイルを同じフォルダーにダウンロードします。\
   このスクリプトは、RealmJoin に必要なすべての権限セットを割り当てます。ロールと権限は次の場所で確認できます： [要件](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md) セクション。必要に応じて JSON ファイルで調整してください。

{% tabs %}
{% tab title="GrantAppPermToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/GrantAppPermToEntApp.ps1>" %}
{% endtab %}

{% tab title="AssignAzureADRoleToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/AssignAzureADRoleToEntApp.ps1>" %}
{% endtab %}

{% tab title="RJvNextPermissions.json" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/RealmJoinVnext/RJvNextPermissions.json>" %}
{% endtab %}

{% tab title="RJvNextRoles.json" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/RealmJoinVnext/RJvNextRoles.json>" %}
{% endtab %}
{% endtabs %}

2. Account Settings > Identity で Azure Automation Account の Managed Identity の Object ID を控えてください

   <figure><img src="/files/8aeef31c277a4dbf352d75304e181d617737a475" alt=""><figcaption></figcaption></figure>
3. PowerShell ウィンドウを開きます。
4. ダウンロードしたファイルが含まれるフォルダーに移動します

```
cd c:\temp\myfolder
```

5. 必要に応じてスクリプトのブロックを解除します\
   ![](/files/000f14430797f2dc09cacdb8829c22d9e00f4cbc)
6. GrantAppPermToEntApp.ps1 を使用して Azure Automation Account に MS Graph の権限を割り当てます。xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx を Automation Account の Object ID に置き換えてください

```
. .\GrantAppPermToEntApp.ps1 -enterpriseAppObjId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -permissionsTemplate .\RJvNextPermissions.json
```

7. AssignAzureADRoleToEntApp.ps1 を使用して Azure Automation Account に Entra ID の管理者ロールを割り当てます。xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx を Automation Account の Object ID に置き換えてください

```
. .\AssignAzureADRoleToEntApp.ps1 -objectId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -rolesTemplate .\RJvNextRoles.json
```

8. これで Azure Automation Account には Runbook を実行するための正しい権限が付与されているはずです<br>
   {% endstep %}

{% step %}

#### RealmJoin Runbook の設定 - パート 1

1. RealmJoin Portal で「[設定 -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'.<br>

   <figure><img src="/files/73e470bc8262e8f5956298238e47bcecc72cbb04" alt=""><figcaption></figcaption></figure>
2. Azure Automation Account に属する Tenant ID、Subscription ID、および Resource Group 名を入力します\
   次の Tenant ID を [Entra ID の概要ページ](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview)

   <figure><img src="/files/4651a9dcb9e1cd6a07d9ec2dcab8ea37dd146eea" alt=""><figcaption></figcaption></figure>
3. 下に赤字で示されているスクリプトをコピーします *ResourceGroup.*\
   このスクリプトは、Entra ID に Service Principal を作成し、Automation Account へのアクセスを付与します。これにより、RealmJoin は runbook の管理、実行、監視を行えるようになります。\
   スクリプトは、Tenant ID、Subscription ID、および Resource Group の入力に基づいて更新されます。<br>

   <figure><img src="/files/5221b368bf8ec49f8d0beb372006fb3e8097d72a" alt=""><figcaption></figcaption></figure>
4. ウィザードは今のところ開いたままにしてください。パート 2 ですぐに戻ります。
   {% endstep %}

{% step %}

#### RealmJoin に Azure Automation へのアクセスを付与する

{% hint style="info" %}
次を使用できます： [Azure CloudShell](https://docs.microsoft.com/en-us/azure/cloud-shell/overview)そのため、ローカルの AZ CLI をインストールして認証する必要はありません。
{% endhint %}

1. 前にコピーしたスクリプトを PowerShell で実行します。

   <figure><img src="/files/9e791e225e968fff364176be96bd3447ce177a15" alt=""><figcaption></figcaption></figure>
2. 次の値を控えてください： `appId` および `password`。\
   App Registration「RealmJoin Runbook Management」が作成されます。<br>

   ![Azure Portal の App Registrations](/files/16ce1f21dd091192d47b796c064d4dd959bb6088)
   {% endstep %}

{% step %}

#### RealmJoin Runbook の設定 - パート 2

1. RealmJoin Portal で開いているウィンドウ/ウィザードに戻り、「[設定 -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'
2. 次の不足している値を入力します： `appId` および `password` 前の手順で作成された
3. 作成した Automation Account の名前を入力します [以前に](#create-an-azure-automation-account)
4. 追跡する共有 runbook リポジトリのブランチを選択します。\
   不明な場合は、次を選択してください： `production`\
   すべての runbook ブランチは次で確認できます： <https://github.com/realmjoin/realmjoin-runbooks>
5. runbook が正しい場所で実行されるように、Azure Automation Account と同じ場所を選択してください [Azure リージョン](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview)

![RealmJoin Portal の Automation Account 接続](/files/7136a85ec0d1d89eb9598c65ba74c02a2590659b)

6. runbook の初回インポートを開始するには、「Save」を押してください。「Sync completed」というメッセージが表示されるまで、このウィンドウを開いたままにしてください。

![](/files/7bca85aae4b6c741b94769171f3a95bd3ef0a4d1)
{% endstep %}
{% endstepper %}


---

# 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.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation.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.
