Walkthrough: Deploy builds using PowerShell/API

This topic describes how to deploy/create builds for Windows OS VMs in PowerShell on a Windows 10 development device based on the Windows Runner C# sample.

Note

In order to use and view the PlayFab Multiplayer Servers, you need to enable the feature. We recommend that you use the Game Manager method to enable this feature. For instructions, see Enable the PlayFab Server feature.

Prerequisites

Make sure you have completed the following steps.

1. Get your title ID and developer secret key

  • Get your PlayFab title ID

    • Log into your developer account on PlayFab.com
    • In Game Manager, go to My Studios and Titles page. Look for your game title and get the PlayFab game title ID
  • Get the developer secret key for the title

    • In Game Manager, select your title > settings (gear icon)
    • Select Title settings, then select the Secret Keys tab to get the developer secret key

For more information about secret keys, see Secret key management

2. Install the PlayFab Multiplayer PowerShell module

Open Windows Powershell as an Administrator and run the following command to install the PlayFabMultiplayer API module. This new PlayFabMultiplayer API module replaces the deprecated Multiplayer PowerShell module.

If you have previously installed PlayFab Multiplayer Powershell module, uninstall it with following command. For those transitioning to the new module, see Mapping commands to find the new equivalent commands.

Uninstall-Package PlayFabMultiplayer

Both the commands and arguments are different in this new module. For detailed documentation about each command, see Cmdlet documentation.

Install-Module -Name PlayFabMultiplayerApi

Tip

Before installing the module, you may need to set your execution policy using Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser first. To learn more, see PowerShell execution policies.

3. Obtain an EntityToken for your title

In the PowerShell window, run the following command using your title ID and associated developer key:

Set-PfTitle -TitleID "mytitleID" -SecretKey "mysecretkey"

4. Upload assets

When you deploy Windows servers, you would use the managed Windows Container. All you have to do is to upload the PlayFab Multiplayer Game Server Build as an asset.

Update the value of the FilePath flag with the local file location of winrunnerSample.zip. If you don't know where this file is, follow the instructions here to get the file.

New-PfAsset -FilePath C:\windowsRunnerCSharp.zip -AssetName windowsRunnerCSharp.zip

5. Create a build

Now that the asset is uploaded, we can create a build. Run the following commands.

The code below uses the Standard_D2as_v4 VM in the EastUS region. Replace strings according to the VM and region you want to use.

$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

Check that your build is successful

In a few seconds, you would see the build created through the PowerShell or ListBuildSummaries API.

You can also run the following command to check that the build deployed successfully.

Get-PfBuild | ConvertTo-Json -depth 5

See also