Blog Post

Power BI Community Blog
2 MIN READ

Get Gateway related information Via PowerShell

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Scenario:

Since October 2019, Power BI has introduced PowerShell Cmdlets to On-premises data gateway. With this set of cmdlets, we can acquire gateway information and complete some gateway management tasks in PowerShell. And in this blog, I will talk about how to use them to get gateway related information.

 

Preparation:

As of now, the supported environment of running these Cmdlets is PowerShell 7.0.6 or higher according to official document PowerShell Cmdlets for On-premises data gateway management (Public Preview). If you don’t have proper version of PowerShell, you may install it from PowerShell Github repository.

Cmdlets related to gateway are available in Data Gateway Module on PowerShell Gallery, so we need to install it with this command in PowerShell:

Install-Module –Name DataGateway

 

Get gateway information via PowerShell:

Before using a specific cmdlet to get gateway information, we need to connect to Data Gateway Service by the following command with appropriate scope. There are two kinds of scopes supported by cmdlets-- individual and organization. With individual scope, only entities related to current user can be accessed. Organization scope can only be used by Global admins and Power BI service admins to access entities of entire tenant.

Connect–DataGatewayServiceAccount

 

Now, we can get gateway information with cmdlets in this module. For example, we can get a list of all Azure regions and the default Power BI region of our tenant.

Get-DataGatewayRegion

 

Also, we can get all gateway cluster and data sources that is added to one cluster or all gateway clusters of which the current user is an admin.

Get-DataGatewayCluster

 

Get-DataGatewayCluster | Get-DataGatewayClusterDatasource

 

As an admin, if you would like to get all gateway cluster within the organization, run this cmdlet with organization scope.

 

In addition, we can use cmdlets in this module to get other gateway information such as data source status, data source users and so on. By executing the following command, we can get entire list of cmdlets contained in this module and have a clear knowledge of what kinds of information we can get with it.

Get-Command -Module DataGateway*

Hope this article can help you understand how to get gateway information via PowerShell.

 

 

Author: Caiyun Zheng 

Reviewer: Ula Huang, Kerry Wang

Updated 4 years ago
Version 2.0

1 Comment

  • NickA01's avatar
    NickA01
    Icon for Resolver III rankResolver III

    I've spent most of the day trying to audit all my org's gateways.  PowerShell is not my core skill set ( Just enough education to perform 🙂 ) 
    After many hours of trying different things, I found this hiding in GitHub 
    PowerBI-cmdlets/PowerBI_Gateway_Overview.ipynb at master · itsnotaboutthecell/PowerBI-cmdlets · GitHub
    Some great examples by AlexPowers & @AaronNelson
    Huge thanks to them for this. ( Wish I'd found it this morning. ) 

     

    Here's the script I've ended up with (Remember you need to be running PoSh 7.x ) and sorry for all the comments. 


    ## check execution policy
    # Get-ExecutionPolicy
    ## enable to run unsigend (only use for trusted sources --IE MSFT)
    # Set-ExecutionPolicy  Unrestricted
    ## gets the required module and checks it's avaliable
    # Import-Module DataGateway
    # Get-Module DataGateway* -ListAvailable
    Login-DataGatewayServiceAccount
    ## Test -- outputs  for aALL Gateways however not status..
    Get-DataGatewayCluster -Scope Organization | Out-File -FilePath D:\Repos\PoShOutput\AllGateways.txt

    ## Seems to fail for GWs where caller is not listed under users..
    $scopeLevel = "Organization"
    $PlatformFile ="D:\Repos\PoShOutput\ALLGWMetaData.json"
    $dataGateways = Get-DataGatewayCluster -Scope $scopeLevel
    $dataGateways | Export-CSV -Path $PlatformFile -NoTypeInformation

    $gateways = @()

    ForEach ($dataGateway in $dataGateways) {

        $gateways += Get-DataGatewayClusterStatus -GatewayClusterId $dataGateway.Id
                    | Select  @{Name="GatewayId"; Expression={ $dataGateway.Id } },@{Name="GatewayName"; Expression={ $dataGateway.Name } }, ClusterStatus,GatewayVersion,GatewayUpgradeState

                                            }


    $outputFile ="D:\Repos\PoShOutput\EntGWMetaData.json"
    $gateways | Export-CSV -Path $outputFile -NoTypeInformation