> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ウォークスルー: PowerShell/API を使用したビルドのデプロイ

> Windows Runner C# サンプルを使用して、PowerShell と Multiplayer Servers API 経由で Windows OS の PlayFab Multiplayer Servers ビルドをデプロイする手順のウォークスルー。

このトピックでは、Windows Runner C# サンプルに基づいて、Windows 10 開発デバイス上の PowerShell を使用して Windows OS VM 用のビルドをデプロイ / 作成する方法について説明します。

<Note>
  PlayFab Multiplayer Servers を利用および表示するには、機能を有効にする必要があります。この機能を有効にする方法として、Game Manager を使用する方法を推奨します。手順については、[PlayFab Server 機能の有効化](/services/playfab/multiplayer/servers/enable-playfab-multiplayer-servers)を参照してください。
</Note>

## 前提条件

以下の手順が完了していることを確認してください。

* [API 機能オプションの構成](/services/playfab/multiplayer/servers/windows-runner-sample#configure-api-feature-option)
* [サーバーのセットアップ](/services/playfab/multiplayer/servers/windows-runner-sample#server-set-up)

## 1. タイトル ID と開発者シークレット キーの取得

* PlayFab タイトル ID の取得
  * [PlayFab.com](https://developer.playfab.com) で開発者アカウントにログインします
  * Game Manager で、**My Studios and Titles** ページに移動します。ゲーム タイトルを探して、PlayFab ゲーム タイトル ID を取得します

* タイトルの開発者シークレット キーの取得
  * Game Manager で、タイトルを選択 > 設定 (歯車アイコン) を選択します
  * **Title settings** を選択し、次に **Secret Keys** タブを選択して開発者シークレット キーを取得します

シークレット キーの詳細については、[Secret key management](/services/playfab/live-service-management/gamemanager/secret-key-management) を参照してください。

## 2. PlayFab Multiplayer PowerShell モジュールのインストール

管理者として Windows Powershell を開き、次のコマンドを実行して [PlayFabMultiplayer API モジュール](https://github.com/PlayFab/MpsPowershell)をインストールします。この新しい [PlayFabMultiplayer API モジュール](https://github.com/PlayFab/MpsPowershell)は、非推奨となった Multiplayer PowerShell モジュールを置き換えるものです。

以前に [PlayFab Multiplayer Powershell](https://github.com/PlayFab/MultiplayerPowershell) モジュールをインストールしたことがある場合は、次のコマンドでアンインストールしてください。新しいモジュールへの移行時には、[コマンドのマッピング](/services/playfab/multiplayer/servers/deploy-using-powershell-api#mapping-commands)を参照して、新しい同等のコマンドを確認してください。

```powershell theme={null}
Uninstall-Package PlayFabMultiplayer
```

この新しいモジュールでは、コマンドと引数の両方が変更されています。各コマンドの詳細なドキュメントについては、[Cmdlet のドキュメント](https://github.com/PlayFab/MpsPowershell/tree/main/MpsPowershell/docs)を参照してください。

```powershell theme={null}
Install-Module -Name PlayFabMultiplayerApi
```

<Tip>
  モジュールをインストールする前に、まず `Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser` を使用して実行ポリシーを設定する必要がある場合があります。詳細については、[PowerShell 実行ポリシー](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies)を参照してください。
</Tip>

## 3. タイトルの EntityToken の取得

**PowerShell** ウィンドウで、タイトル ID と関連する開発者キーを使用して次のコマンドを実行します。

```powershell theme={null}
Set-PfTitle -TitleID "mytitleID" -SecretKey "mysecretkey"
```

## 4. アセットのアップロード

Windows サーバーをデプロイする場合、マネージド Windows コンテナーを使用します。必要なのは、PlayFab Multiplayer Game Server Build をアセットとしてアップロードすることだけです。

**FilePath** フラグの値を **winrunnerSample.zip** のローカル ファイルの場所に更新します。このファイルの場所がわからない場合は、[こちら](/services/playfab/multiplayer/servers/windows-runner-sample#server-set-up)の手順に従ってファイルを取得してください。

```powershell theme={null}
New-PfAsset -FilePath C:\windowsRunnerCSharp.zip -AssetName windowsRunnerCSharp.zip
```

## 5. ビルドの作成

アセットがアップロードされたので、ビルドを作成できます。以下のコマンドを実行してください。

以下のコードでは、**EastUS** リージョンの **Standard\_D2as\_v4** VM を使用します。使用したい VM とリージョンに応じて文字列を置き換えてください。

```powershell theme={null}
$vmSize = "Standard_D2as_v4"

$regions = @( @{ StandbyServers = 1; MaxServers = 1; Region = 'EastUS'; ScheduledStandbySettings = $NULL } )

$ports = @( @{ Name = 'game_port'; Num = 3600; Protocol = 'TCP' } )

$gameAssets = @( @{ FileName = 'windowsRunnerCSharp.zip'; MountPath = 'C:\Assets' } )

$buildResponse = New-PfBuild -BuildName PSTest_build -ContainerFlavor ManagedWindowsServerCore -StartMultiplayerServerCommand 'C:\Assets\WindowsRunnerCSharp.exe' -GameAssetReferences $gameAssets -VMSize $vmSize -MultiplayerServerCountPerVM 1 -Ports $ports -RegionConfigurations $regions

# All PlayFabMultiplayerApi cmdlets return objects, so we can pass the returned object to ConvertTo-Json for human readability.
$buildResponse | ConvertTo-Json -depth 5
```

## ビルドが成功していることの確認

数秒後、**PowerShell** または [ListBuildSummaries API](xref:titleid.playfabapi.com.multiplayer.multiplayerserver.listbuildsummariesv2) からビルドが作成されたことが確認できます。

また、次のコマンドを実行して、ビルドが正常にデプロイされたことを確認することもできます。

```powershell theme={null}
Get-PfBuild | ConvertTo-Json -depth 5
```

## 関連項目

* [ウォークスルー: Game Manager を使用したビルドのデプロイ](/services/playfab/multiplayer/servers/quickstart-for-multiplayer-servers-game-manager)
* [Windows Runner C# サンプル](/services/playfab/multiplayer/servers/windows-runner-sample)
* [サンプルとリソース](/services/playfab/multiplayer/servers/server-samples-resources)


## Related topics

- [PowerShell/API を使用したビルドのデプロイ](/ja-jp/services/playfab/multiplayer/servers/deploy-using-powershell-api.md)
- [PlayFab マルチプレイヤー サーバー ビルドのデプロイ](/ja-jp/services/playfab/multiplayer/servers/deploying-playfab-multiplayer-server-builds.md)
- [シークレットの管理 (プレビュー)](/ja-jp/services/playfab/multiplayer/servers/manage-secrets.md)
- [Linux ビルドの作成とデプロイ](/ja-jp/services/playfab/multiplayer/servers/deploying-linux-based-builds.md)
- [Visual Studio を使用した XBOX プロジェクトのデバッグ](/ja-jp/tools/tools-console/visualstudio/debugging-with-visualstudio.md)
