Showing results for 
Search instead for 
Did you mean: 
Regular Visitor

How to remove the Power BI gateway using PowerShell or REST API

Hi team


We are trying to delete Power BI gateway by using PowerShell module or REST API.


We tried to use DataGateway PowerShell module to get the gateway first and remove it using the comdlets below.


     $PowerBIDataGatewayCluster = Get-DataGatewayCluster
     if ($null -ne $PowerBIDataGatewayCluster -and "" -ne $PowerBIDataGatewayCluster) {
         Write-Host "Revoke admin access for SPN from Power BI gateway $($PowerBIDataGatewayCluster.Name)"
          Remove-DataGatewayCluster -GatewayClusterId $PowerBIDataGatewayCluster.Id



It works well with my Azure accounts without any issue.


However, if we use the service principal, even if the service principal has the admin access to the PowerBI gateway,

the cmdlet is still not able to get the gateway or remove it. And I am getting unauthoried error.


Is that because the Power BI powershell moduel does not support Service Principal authencation?


Is there anyway we could automate this process?



Super User
Super User

Why would you want to automate that operation?  You don't want to mess with a gateway configuration unless absolutely necessary. Removing a gateway cluster member should be done judiciously (and can be done via the admin center UI too).

Hi @lbendlin 


This is a buiness requirement. We have one gateway for each customer and we would like to remove it once the customer is offboarded.


Yes, we noticed that the PowerShell cmdlet is able to remove the members 


But we would like to remove the gateway itself as well, otherwise we will have heaps of gatway without being used anymore.

If you must - there is a choreography to it.


1. List all gateways and all cluster members

2. Identify the anchor member

3. for each gateway, remove the members that are NOT the anchor

4. remove the anchor member.


Hint:  The gatewayObjectId of the anchor member is the clusterObjectID


Note:  This only removes the meta data on the Power BI Service. It does not do anything to your VMs.

Thanks @lbendlin 


Does this mean we still could only remove the members from the gateway?


I am trying to remove the gateway itself by using PowerShell or REST API using Service Principal.

When you remove the anchor member the entire gateway registration will be gone and all connections on that gateway too.

Hi @lbendlin 


Thanks for the replies.


May I know what the anchor member is here?


We only have the Azure Service Principal Assigned to the Gateway, which is the admin for the gateway as well.


Is the Azure Service Principal the anchor member in this case?


The anchor member is the primary VM registered as a gateway in a gateway cluster.  It is a machine identifier, not a login identifier.

Hi @lbendlin 


Thanks for the reply.


What we are trying to do is to remove the whole gateway cluster by using service principal via PowerShell module or REST API, rather than removing individual gateway from the cluster.


Is it supported at the moment? If so, could we know what permissions are required for the service principal?


There is no such thing. You need to remove the gateway cluster members individually.

This cmdlet could remove the application gateway cluster though.

Remove-DataGatewayCluster (DataGateway) | Microsoft Learn


But it seems to be working with the actual Azure account, not the service principal?

Oh wow, they added a lot of new cmdlets.  The cmdlet probable enumerates the cluster members and deletes them one by one for you. Fair enough.


As for the service principal question - i'll have to try that on our side.  Don't see any mention of limitations at the moment.

Hey @lbendlin 


Yeah I know, the limitations are not mentioned in the doc, but...


Have you tried that from your end?

or is there any way we could connect to MS support directly on this?

You can raise an issue at . If you have a Pro license you can consider raising a Pro ticket at

Helpful resources


2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.