Firstly, start PowerShell ISE as an administrator. The Windows PowerShell Integrated Scripting Environment (ISE) is the host application for Windows PowerShell. In ISE, you can run commands and write, test, and debug scripts in a single Windows-based graphical user interface.
Secondly, In order to manage the connection to Power BI Service, we need to install “MicrosoftPowerBIMgmt”. We can use the visual interface of PowerShell ISE to add this module, or use the command to add. Please refer to the link.
The first step we need to do is to use the “Connect-PowerBIServiceAccount” command to connect to the Power BI Service, and then use the “Get-PowerBIWorkspace” command to get the information of the workspace on the Power BI Service and assign it to the variable “Workspaces”.
$Workspaces = Get-PowerBIWorkspace –All
Secondly, we need to use the function “ForEach()” to traverse the parameters “$Workspaces” and “Get-PowerBIDataset -WorkspaceId $workspace.Id”, and then output the data set lists in the corresponding Workspaces.
ForEach ($workspace in $Workspaces)
ForEach ($dataset in (Get-PowerBIDataset -WorkspaceId $workspace.Id))
WorkspaceName = $Workspace.Name
WorkspaceID = $workspace.Id
DatasetName = $dataset.Name
DatasetID = $dataset.Id
Finally, export the results of the parameter “$Datasets” to a local .csv file and Disconnect current connection.
2. Get the lists of workspaces and data sets in PowerShell.
A RESTful API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources. For Power BI Service, Microsoft officially provides many Rest APIs for developers to use.
Here we use the “Get Dataset API”. First, we still need to connect to the Power BI Service, and then use the “Get-PowerBIWorkspace” command to get the data of the workspace and assign it to the parameter "$Workspace".
$Workspace = Get-PowerBIWorkspace –All
Second and most important, we need to use the “Invoke-PowerBIRestMethod” command to access the API and return JSON information. Please refer to the link.
The above content introduces how to use PowerShell to connect to Power BI Service, how to get the content in Power BI Service through command codes, and how to use Rest API in PowerShell. These are just basic content. In fact, PowerShell has more abundant features, including the realization of report refresh, log monitoring and realization of certain automatic features. Last but not least, Power BI REST APIs have some limitations, please refer to this document for details.