Create or change a Peering Service connection using PowerShell

Azure Peering Service is a networking service that enhances connectivity to Microsoft cloud services such as Microsoft 365, Dynamics 365, software as a service (SaaS) services, Azure, or any Microsoft services accessible via the public internet.

In this article, you'll learn how to create and change a Peering Service connection using PowerShell.

If you don't have an Azure subscription, create a free account before you begin.

Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.

To start Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell. Screenshot that shows an example of Try It for Azure Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. Screenshot that shows how to launch Cloud Shell in a new window.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. Screenshot that shows the Cloud Shell button in the Azure portal

To use Azure Cloud Shell:

  1. Start Cloud Shell.

  2. Select the Copy button on a code block (or command block) to copy the code or command.

  3. Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.

  4. Select Enter to run the code or command.

If you decide to install and use PowerShell locally instead, this article requires you to use Azure PowerShell module version 1.0.0 or later. To find the installed version, run Get-Module -ListAvailable Az. For installation and upgrade information, see Install Azure PowerShell module.

Finally, if you're running PowerShell locally, you'll also need to run Connect-AzAccount. That command creates a connection with Azure.

Use the Azure PowerShell module to register and manage Peering Service. You can register or manage Peering Service from the PowerShell command line or in scripts.

Prerequisites

Register your subscription with the resource provider and feature flag

Before you proceed to the steps of creating Peering Service, register your subscription with the resource provider and feature flag using Register-AzResourceProvider and Register-AzProviderFeature:

# Register Microsoft.Peering provider.
Register-AzResourceProvider -ProviderNamespace Microsoft.Peering
# Register AllowPeeringService feature.
Register-AzProviderFeature -FeatureName AllowPeeringService -ProviderNamespace Microsoft.Peering 

List Peering Service locations and service providers

Use Get-AzPeeringServiceCountry to list the countries where Peering Service is available and Get-AzPeeringServiceLocation to list the available metro locations in each country where you can get the Peering Service:

# List the countries available for Peering Service.
Get-AzPeeringServiceCountry 
# List metro locations serviced in a country
Get-AzPeeringServiceLocation -Country "United States"

Use Get-AzPeeringServiceProvider to get a list of available Peering Service providers:

Get-AzPeeringServiceProvider

Create a Peering Service connection

Create a Peering Service connection using New-AzPeeringService:

New-AzPeeringService -ResourceGroupName myResourceGroup -Name myPeeringService -PeeringLocation Virginia -PeeringServiceProvider Contoso

Add the Peering Service prefix

Use New-AzPeeringServicePrefix to add the prefix provided to you by the connectivity provider:

New-AzPeeringServicePrefix -ResourceGroupName myResourceGroup -PeeringServiceName myPeeringService -Name myPrefix -prefix 240.0.0.0/32 -ServiceKey 00000000-0000-0000-0000-000000000000

List all Peering Services connections

To view the list of all Peering Service connections, use Get-AzPeeringService:

Get-AzPeeringService | Format-Table Name, PeeringServiceLocation, PeeringServiceProvider, Location

List all Peering Service prefixes

To view the list of all Peering Service prefixes, use Get-AzPeeringServicePrefix:

Get-AzPeeringServicePrefix -PeeringServiceName myPeeringService -ResourceGroupName myResourceGroup

Remove the Peering Service prefix

To remove the Peering Service prefix, use Remove-AzPeeringServicePrefix:

Remove-AzPeeringServicePrefix -ResourceGroupName myResourceGroup -Name myPeeringService -PrefixName myPrefix

Next steps