Quickstart: Create a private endpoint by using Azure PowerShell (2023)

  • Article
  • 7 minutes to read

Get started with Azure Private Link by using a private endpoint to connect securely to an Azure web app.

In this quickstart, you'll create a private endpoint for an Azure web app and then create and deploy a virtual machine (VM) to test the private connection.

You can create private endpoints for various Azure services, such as Azure SQL and Azure Storage.


  • An Azure account with an active subscription. If you don't already have an Azure account, create an account for free.

  • An Azure web app with a PremiumV2-tier or higher app service plan, deployed in your Azure subscription.

    • For more information and an example, see Quickstart: Create an ASP.NET Core web app in Azure.

    • The example webapp in this article is named myWebApp1979. Replace the example with your webapp name.

If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. To find the installed version, run Get-Module -ListAvailable Az. If you need to upgrade, see Install the Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.

Create a resource group

An Azure resource group is a logical container where Azure resources are deployed and managed.

Create a resource group with New-AzResourceGroup:

(Video) How to Create a private endpoint using Azure PowerShell

New-AzResourceGroup -Name 'CreatePrivateEndpointQS-rg' -Location 'eastus'

Create a virtual network and bastion host

A virtual network and subnet is required for to host the private IP address for the private endpoint. You'll create a bastion host to connect securely to the virtual machine to test the private endpoint. You'll create the virtual machine in a later section.

In this section, you'll:

## Configure the back-end subnet. ##$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name myBackendSubnet -AddressPrefix Create the Azure Bastion subnet. ##$bastsubnetConfig = New-AzVirtualNetworkSubnetConfig -Name AzureBastionSubnet -AddressPrefix Create the virtual network. ##$net = @{ Name = 'MyVNet' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' AddressPrefix = '' Subnet = $subnetConfig, $bastsubnetConfig}$vnet = New-AzVirtualNetwork @net## Create the public IP address for the bastion host. ##$ip = @{ Name = 'myBastionIP' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' Sku = 'Standard' AllocationMethod = 'Static' Zone = 1,2,3}$publicip = New-AzPublicIpAddress @ip## Create the bastion host. ##$bastion = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'myBastion' PublicIpAddress = $publicip VirtualNetwork = $vnet}New-AzBastion @bastion -AsJob

Create a private endpoint

An Azure service that supports private endpoints is required to set up the private endpoint and connection to the virtual network. For the examples in this article, we're using an Azure WebApp from the prerequisites. For more information on the Azure services that support a private endpoint, see Azure Private Link availability.

A private endpoint can have a static or dynamically assigned IP address.


You must have a previously deployed Azure WebApp to proceed with the steps in this article. For more information, see Prerequisites.

In this section, you'll:

(Video) Quickstart: Create a virtual network using PowerShell - Azure VM Deployment

  • Create a private link service connection with New-AzPrivateLinkServiceConnection.

  • Create the private endpoint with New-AzPrivateEndpoint.

  • Optionally create the private endpoint static IP configuration with New-AzPrivateEndpointIpConfiguration.

  • Dynamic IP
  • Static IP
## Place the previously created webapp into a variable. ##$webapp = Get-AzWebApp -ResourceGroupName CreatePrivateEndpointQS-rg -Name myWebApp1979## Create the private endpoint connection. ## $pec = @{ Name = 'myConnection' PrivateLinkServiceId = $webapp.ID GroupID = 'sites'}$privateEndpointConnection = New-AzPrivateLinkServiceConnection @pec## Place the virtual network you created previously into a variable. ##$vnet = Get-AzVirtualNetwork -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Name 'myVNet'## Create the private endpoint. ##$pe = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'myPrivateEndpoint' Location = 'eastus' Subnet = $vnet.Subnets[0] PrivateLinkServiceConnection = $privateEndpointConnection}New-AzPrivateEndpoint @pe

Configure the private DNS zone

A private DNS zone is used to resolve the DNS name of the private endpoint in the virtual network. For this example, we're using the DNS information for an Azure WebApp, for more information on the DNS configuration of private endpoints, see Azure Private Endpoint DNS configuration.

In this section, you'll:

## Place the virtual network into a variable. ##$vnet = Get-AzVirtualNetwork -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Name 'myVNet'## Create the private DNS zone. ##$zn = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'privatelink.azurewebsites.net'}$zone = New-AzPrivateDnsZone @zn## Create a DNS network link. ##$lk = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' ZoneName = 'privatelink.azurewebsites.net' Name = 'myLink' VirtualNetworkId = $vnet.Id}$link = New-AzPrivateDnsVirtualNetworkLink @lk## Configure the DNS zone. ##$cg = @{ Name = 'privatelink.azurewebsites.net' PrivateDnsZoneId = $zone.ResourceId}$config = New-AzPrivateDnsZoneConfig @cg## Create the DNS zone group. ##$zg = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' PrivateEndpointName = 'myPrivateEndpoint' Name = 'myZoneGroup' PrivateDnsZoneConfig = $config}New-AzPrivateDnsZoneGroup @zg

Create a test virtual machine

To verify the static IP address and the functionality of the private endpoint, a test virtual machine connected to your virtual network is required.

In this section, you'll:

(Video) Creating an Azure Private Endpoint Connection with Azure Storage Accounts

  • Create a sign-in credential for the virtual machine with Get-Credential

  • Create a network interface for the virtual machine with New-AzNetworkInterface

  • Create a virtual machine configuration with New-AzVMConfig, Set-AzVMOperatingSystem, Set-AzVMSourceImage, and Add-AzVMNetworkInterface

  • Create the virtual machine with New-AzVM

## Create the credential for the virtual machine. Enter a username and password at the prompt. ##$cred = Get-Credential## Place the virtual network into a variable. ##$vnet = Get-AzVirtualNetwork -Name myVNet -ResourceGroupName CreatePrivateEndpointQS-rg## Create a network interface for the virtual machine. ##$nic = @{ Name = 'myNicVM' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' Subnet = $vnet.Subnets[0]}$nicVM = New-AzNetworkInterface @nic## Create the configuration for the virtual machine. ##$vm1 = @{ VMName = 'myVM' VMSize = 'Standard_DS1_v2'}$vm2 = @{ ComputerName = 'myVM' Credential = $cred}$vm3 = @{ PublisherName = 'MicrosoftWindowsServer' Offer = 'WindowsServer' Skus = '2019-Datacenter' Version = 'latest'}$vmConfig = New-AzVMConfig @vm1 | Set-AzVMOperatingSystem -Windows @vm2 | Set-AzVMSourceImage @vm3 | Add-AzVMNetworkInterface -Id $nicVM.Id## Create the virtual machine. ##New-AzVM -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Location 'eastus' -VM $vmConfig


Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the back-end pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.

The default outbound access IP is disabled when a public IP address is assigned to the VM, the VM is placed in the back-end pool of a standard load balancer, with or without outbound rules, or if an Azure Virtual Network NAT gateway resource is assigned to the subnet of the VM.

VMs that are created by virtual machine scale sets in flexible orchestration mode don't have default outbound access.

For more information about outbound connections in Azure, see Default outbound access in Azure and Use source network address translation (SNAT) for outbound connections.

Test connectivity with the private endpoint

Use the VM you created in the previous step to connect to the webapp across the private endpoint.

  1. Sign in to the Azure portal.

    (Video) Learn how to Create Azure Virtual Network using POWERSHELL Commands

  2. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines.

  3. Select myVM.

  4. On the overview page for myVM, select Connect, and then select Bastion.

  5. Enter the username and password that you used when you created the VM. Select Connect.

  6. After you've connected, open PowerShell on the server.

  7. Enter nslookup mywebapp1979.azurewebsites.net. Replace mywebapp1979 with the name of the web app that you created earlier. You'll receive a message that's similar to the following example:

    Server: UnKnownAddress: answer:Name: mywebapp1979.privatelink.azurewebsites.netAddress: mywebapp1979.azurewebsites.net
  8. In the bastion connection to myVM, open the web browser.

  9. Enter the URL of your web app, https://mywebapp1979.azurewebsites.net.

    If your web app hasn't been deployed, you'll get the following default web app page:

    Quickstart: Create a private endpoint by using Azure PowerShell (1)

  10. Close the connection to myVM.

Clean up resources

When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group, virtual network, and the remaining resources.

(Video) Using PowerShell with Microsoft Endpoint Manager

Remove-AzResourceGroup -Name 'CreatePrivateEndpointQS-rg'

Next steps

For more information about the services that support private endpoints, see:

What is Azure Private Link?


How do I create a private endpoint in Azure command line? ›

Configure the private DNS zone

Create a new private Azure DNS zone with az network private-dns zone create. Link the DNS zone to the virtual network you created previously with az network private-dns link vnet create. Create a DNS zone group with az network private-endpoint dns-zone-group create.

How do I start an Azure portal in PowerShell? ›

Run Command in Azure Portal

In the Azure portal, navigate to the virtual machine resource. Navigate to Operations > Run Command. Select RunPowerShellScript from the list of commands. Type the PowerShell script content you want to run on the server in the Run Command Script pane.

What is the difference between private link and private endpoint in Azure? ›

The private endpoint must be deployed in the same region and subscription as the virtual network. The private-link resource can be deployed in a different region than the one for the virtual network and private endpoint.

What is PowerShell command to add a private link configuration to application gateway? ›

The Add-AzApplicationGatewayPrivateLinkConfiguration cmdlet adds a private link configuration to an application gateway.

What is Azure private endpoint? ›

A private endpoint is a special network interface for an Azure service in your Virtual Network (VNet). When you create a private endpoint for your storage account, it provides secure connectivity between clients on your VNet and your storage.

What is difference between private endpoint and service endpoint? ›

A Service Endpoint remains a publicly routable IP address. A Private Endpoint is a private IP in the address space of the virtual network where the private endpoint is configured.

How do I create a private endpoint for key vault? ›

Create a new key vault and establish a private link connection
  1. Select the Private Endpoint radio button in the Networking tab.
  2. Select the "+ Add" Button to add a private endpoint.
  3. In the "Location" field of the Create Private Endpoint Blade, select the region in which your virtual network is located.
Jan 18, 2023

Can PowerShell run Azure CLI commands? ›

Azure CLI can be run in both PowerShell and CMD, but PowerShell gives you more tab-completion features.

Can I use Azure CLI commands in PowerShell? ›

The Azure CLI is a succinct and powerful automation tool for Azure deployments that should be considered when using PowerShell scripts to orchestrate deployments. It is easily integrated into PowerShell scripts if the running machine has the Azure CLI installed by using the Invoke-Expression cmdlet.

Can we run Azure CLI commands in PowerShell? ›

You can now run the Azure CLI with the az command from either Windows Command Prompt or PowerShell.

What is the PowerShell command to Connect to Azure portal? ›

To sign in interactively, use the Connect-AzAccount cmdlet. This cmdlet presents an interactive browser based login prompt by default. Use the Get-AzContext cmdlet to store your tenant ID in a variable to be used in the next two sections of this article.

Is Azure PowerShell the same as PowerShell? ›

Azure PowerShell is set of cmdlets packaged as a PowerShell module named Az ; not an executable. Windows PowerShell or PowerShell must be used to install the Az module. Windows PowerShell is the standard scripting shell that comes preinstalled with most Windows operating systems.

How do I run Azure function in PowerShell? ›

To execute the Azure function with PowerShell, you must get the endpoint to query. To do that, open the function, click on Code + Test, and then on Get function URL. You'll see an option for selecting a Key. This key comes from the authentication level when you create the Function App.

How do I use Azure private endpoint? ›

Test connectivity to private endpoint
  1. Select Resource groups in the left-hand navigation pane.
  2. Select myResourceGroup.
  3. Select myVM.
  4. On the overview page for myVM, select Connect then Bastion.
  5. Enter the username and password that you entered during the virtual machine creation.
  6. Select Connect button.
Jun 22, 2022

How do I use a private endpoint in Azure SQL? ›

If you don't have an Azure subscription, create a free account before you begin.
  1. Prerequisites. ...
  2. Sign in to Azure. ...
  3. Create a virtual network and bastion host. ...
  4. Create a virtual machine. ...
  5. Create an Azure SQL server and private endpoint. ...
  6. Disable public access to Azure SQL logical server. ...
  7. Test connectivity to private endpoint.
Jun 22, 2022

How do I create a private application gateway in Azure? ›

To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
  1. Sign in to Azure. Sign in to the Azure portal.
  2. Create an application gateway. ...
  3. Add backend pool. ...
  4. Create a client virtual machine. ...
  5. Test the application gateway. ...
  6. Next steps.
Oct 20, 2022

What is the PowerShell cmdlet to add a computer to a domain? ›

The Add-Computer cmdlet adds the local computer or remote computers to a domain or workgroup, or moves them from one domain to another. It also creates a domain account if the computer is added to the domain without an account.

What is $Profile PowerShell? ›

The $PROFILE automatic variable stores the paths to the PowerShell profiles that are available in the current session. To view a profile path, display the value of the $PROFILE variable. You can also use the $PROFILE variable in a command to represent a path.

What Azure services support private endpoint? ›

Azure Private Link enables you to access Azure PaaS Services (for example, Azure Storage and SQL Database) and Azure hosted customer-owned/partner services over a private endpoint in your virtual network.

How do I create a NIC in Azure? ›

Step 1: Click on Create resource button and type-in network interface. Then click on Network Interface and create. Step 2: Now, fill the required details and click on create. Step 3: Your Network Interface will be created and ready to embed.

How does private link work in Azure? ›

Azure Private Link provides private connectivity from a virtual network to Azure platform as a service (PaaS), customer-owned, or Microsoft partner services. It simplifies the network architecture and secures the connection between endpoints in Azure by eliminating data exposure to the public internet.

What is a common example of an endpoint? ›

Some examples of endpoints are mobile devices, desktop computers, virtual machines, embedded devices, and servers. Internet-of-Things devices—like cameras, lighting, refrigerators, security systems, smart speakers, and thermostats—are also endpoints.

What is private endpoint in Azure data Factory? ›

By using Azure Private Link, you can connect to various platform as a service (PaaS) deployments in Azure via a private endpoint. A private endpoint is a private IP address within a specific virtual network and subnet.

How do I Create a secret Azure key vault in powershell? ›

The Set-AzKeyVaultSecret cmdlet creates or updates a secret in a key vault in Azure Key Vault. If the secret does not exist, this cmdlet creates it. If the secret already exists, this cmdlet creates a new version of that secret.

How do I Create a managed private endpoint in Azure data Factory? ›

Create a managed private endpoint
  1. Go to the Manage tab. ...
  2. Go to the Managed private endpoints section.
  3. Select + New under Managed private endpoints.
  4. Select the Azure Blob Storage tile from the list, and select Continue.
  5. Enter the name of the storage account you created.
  6. Select Create.
Sep 27, 2022

Can Azure key vault generate keys? ›

Add a key to Key Vault

On the Key Vault properties pages, select Keys. Select Generate/Import. On the Create a key screen choose the following values: Options: Generate.

What is the difference between Azure PowerShell and Azure CLI? ›

Azure CLI vs Azure PowerShell:

While both are cross-platform and installable on Windows, macOS, and Linux, Azure CLI runs in Windows PowerShell, Cmd, or Bash and other Unix shells whereas Azure PowerShell requires Windows PowerShell or PowerShell.

How do I run an Azure script from PowerShell? ›

Assuming you have an existing Azure subscription, here are the steps to create an automated scheduled task in Azure at the high level:
  1. Create an Azure Automation Account.
  2. Setup Credentials to connect to SharePoint Online.
  3. Import Necessary Modules.
  4. Create a Runbook and add scripts to run.
  5. Schedule the PowerShell Script.
Jan 8, 2023

Will Azure CLI works inside of PowerShell? ›

Azure CLI is cross-platform command-line tool for managing Azure resources, and it can run in Windows, Mac and Linux. This also means it can run on Windows PowerShell. Its more flexible than Azure PowerShell since its a binary and can run inside any OS default shell.

Can I use PowerShell instead of CMD? ›

For those who prefer using Command Prompt, you can opt out of the Windows Logo Key + X change by opening Settings > Personalization > Taskbar, and turning off, Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X.

Can PowerShell run all CMD commands? ›

PowerShell is a command-line shell and a scripting language used for automation. Similar to other shells, like bash on Linux or the Windows Command Shell ( cmd.exe ), PowerShell lets you to run any command available on your system, not just PowerShell commands.

What is the benefit of using PowerShell over CLI? ›

The real biggest benefit of Powershell is that it operates on objects, not on strings. Therefore it's really easy to work with output of commands: $t = Get-AzEventGridTopic ... ; $endpoint = $t. Endpoint . With Azure CLI you would have to parse strings for that.

Can Azure PowerShell run in browser? ›

Azure Windows PowerShell: The Azure PowerShell Module will help you to manage your Azure resources. You can use it on your local machine or in your web browser.

How do I run Azure API in PowerShell? ›

To use the Azure Rest API using PowerShell, we first need to connect to the Azure cloud account using the Connect-AzAccount. Once you are connected to the Azure Account, you can use the below authorization header (same has been provided on the MS website) which contains a bearer token to authenticate the rest API.

How do I create a database with Azure portal using PowerShell script? ›

Steps for creating an Azure SQL Database using Azure PowerShell
  1. Step 1: Connect to Azure account. ...
  2. Step 2: Create an Azure Resource Group. ...
  3. Step 4: Configure the Server Firewall Rule. ...
  4. Step 5: Connect to Azure SQL database and creates a new database. ...
  5. Step 6: Query the Azure SQL database for validations.
Mar 10, 2021

How do I connect to Azure VM from Windows PowerShell? ›

Open a web browser and go to https://portal.azure.com.
To consider this lab complete, please perform the following:
  1. Log in to the Azure Portal and open a Cloud Shell PowerShell prompt.
  2. Establish a new PowerShell remote session.
  3. Using the established session, connect to the VM and verify that you are on a Windows VM.

When to use Azure PowerShell? ›

Azure PowerShell is designed for managing and administering Azure resources from the command line. Use Azure PowerShell when you want to build automated tools that use the Azure Resource Manager model. Try it out in your browser with Azure Cloud Shell, or install on your local machine.

Is Azure PowerShell free? ›

It's free and easy to use. Another alternative to Azure PowerShell involves not using Azure at all.

Is PowerShell more powerful than command prompt? ›

PowerShell is significantly more powerful and rich in capabilities compared to CMD.exe; it's able to manage hundreds of machines across different platforms whereas CMD.exe is only capable of executing much simpler tasks on a smaller scale.

What does F7 do in PowerShell? ›

If you have been entering several commands in a console screen, pressing the F7 function key displays a menu of the previously executed commands, as Figure 2.2 shows. Figure 2.2. Pressing the F7 function key presents a command history menu. Use the arrow keys to change the selection in the menu.

Can Azure PowerShell run on Windows? ›

Simply put, PowerShell is a scripting language and command-line shell that's made by Microsoft to serve as a task automation solution. Though it started as a Windows exclusive, it's now cross-platform and runs on Linux, macOS, and Windows.

How do I create a client secret in PowerShell Azure? ›

Get Client Secret Id

From left Menu of Azure Directory -> click App Registration -> Click the name of the application created in the previous step, in my case name will be GeeksAPI. Click on New Client Secret from right side pane -> Add description and expiration in Add a Client Secret screen -> Click Add button.

How do I create a private endpoint for Azure SQL Database? ›

Select the Networking tab or select the Next: Networking button. Select Private endpoint. Select + Add private endpoint in Private endpoints. Select your subscription.

What is the Private endpoint in Azure? ›

A private endpoint is a special network interface for an Azure service in your Virtual Network (VNet). When you create a private endpoint for your storage account, it provides secure connectivity between clients on your VNet and your storage.

How do I get client secret in PowerShell? ›

First, connect to your Azure AD using the PowerShell Connect-AzureAD cmdlet. Next, use the Get-AzureADServicePrincipal cmdlet to get the app, specifying the app's client ID and a new client secret.

How do I create a client secret in Azure? ›

Option 2: Create a new application secret
  1. Select Azure Active Directory.
  2. From App registrations in Azure AD, select your application.
  3. Select Certificates & secrets.
  4. Select Client secrets -> New client secret.
  5. Provide a description of the secret, and a duration. When done, select Add.
Jan 20, 2023

How do I generate client ID and client secret Azure? ›

1 answer
  1. Login to the Azure Portal.
  2. Navigate to Azure Active Directory.
  3. Select App Registrations , locate the Azure AD App that you're trying to find the Client ID and Client Secret Key for.
  4. Within the Azure AD App, select Certificates & Secrets.
May 2, 2022

How do I create a private and public subnet in Azure? ›

Select + Add subnet, then enter Public for Subnet name and 10.0. 0.0/24 for Subnet address range. Select Add. Select + Add subnet, then enter Private for Subnet name and 10.0.

How do I make an Azure private dashboard? ›

Create a new dashboard
  1. Sign in to the Azure portal.
  2. From the Azure portal menu, select Dashboard. ...
  3. Select New dashboard, then select Blank dashboard. ...
  4. Select the My Dashboard text in the dashboard label and enter a name that will help you easily identify the custom dashboard.
May 11, 2022

What are the steps to create private endpoint in Azure data Factory? ›

On the Azure portal page for your data factory, select Networking > Private endpoint connections and then select + Private endpoint. Select your subscription. Select a resource group. Enter a name for your endpoint.

How do I create a managed private endpoint in Azure data Factory? ›

Create a managed private endpoint
  1. Go to the Manage tab. ...
  2. Go to the Managed private endpoints section.
  3. Select + New under Managed private endpoints.
  4. Select the Azure Blob Storage tile from the list, and select Continue.
  5. Enter the name of the storage account you created.
  6. Select Create.
Sep 27, 2022


1. Getting Started with Azure PowerShell
(John Savill's Technical Training)
2. Create Resources Using Azure CLI and PowerShell
3. Using PowerShell with Azure Conditional Access
(Robert Crane)
4. Create a vNet in Azure with PowerShell
(Michael Levan)
5. Microsoft Azure Private Link Deep Dive
(John Savill's Technical Training)
6. AZ 104 Lab 03c Manage Azure resources by Using Azure PowerShell - Labs from Github Completed
(Cloud Security Training & Consulting)
Top Articles
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated: 02/09/2023

Views: 5901

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.