{"id":41358,"date":"2025-05-30T11:56:53","date_gmt":"2025-05-30T06:26:53","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=41358"},"modified":"2025-05-30T11:56:53","modified_gmt":"2025-05-30T06:26:53","slug":"automating-power-bi-report-export-and-import-using-powershell","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2025\/05\/automating-power-bi-report-export-and-import-using-powershell\/","title":{"rendered":"Automating Power BI Report Export and Import Using PowerShell"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-41365\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25.png\" alt=\"Power BI Report Export and Import Using PowerShell\" width=\"1925\" height=\"1100\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25.png 1925w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25-300x171.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25-1024x585.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25-768x439.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25-1536x878.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/05\/Technical-blog-30-05-25-660x377.png 660w\" sizes=\"(max-width: 1925px) 100vw, 1925px\" \/><\/p>\n<p>Power BI has become an essential tool for business intelligence and reporting.<\/p>\n<p>However, managing Power BI reports across different environments or workspaces can be time-consuming and error-prone.<\/p>\n<p>PowerShell offers an efficient and reliable method to automate the export and import of Power BI reports.<\/p>\n<p>In this blog post, we\u2019ll walk through how to use PowerShell to export Power BI reports from one workspace and import them into another. We\u2019ll also cover how to update dataset parameters and refresh datasets after the import.<\/p>\n<h3>Prerequisites<\/h3>\n<ol>\n<li><strong>Power BI Management Module:<\/strong> Open PowerShell and run the following command to install the MicrosoftPowerBIMgmt module:<br \/>\nInstall-Module -Name MicrosoftPowerBIMgmt<\/li>\n<li><strong>Power BI Account<\/strong>: You need access to the Power BI service with sufficient permissions to export and import reports.<\/li>\n<li><strong>PowerShell<\/strong>: Ensure you\u2019re using PowerShell 5.1 or later.<\/li>\n<\/ol>\n<h3><strong>Step 1: Authenticate to Power BI Service<\/strong><\/h3>\n<p>To interact with Power BI, you need to authenticate. There are multiple ways to authenticate:<\/p>\n<ul>\n<li><strong>Interactive Login<\/strong>: Use this method if you want to log in interactively.<\/li>\n<\/ul>\n<p>Connect-PowerBIServiceAccount<\/p>\n<ul>\n<li><strong>User login<\/strong>: Use this method for non-interactive authentication.<\/li>\n<\/ul>\n<pre class=\"lang:css gutter:true start:1\">$username = \u201c\u201d\r\n$password = \u201c\u201d | ConvertTo-SecureString -asPlainText -Force\r\n\r\n$credential = New-Object System.Management.Automation.PSCredential($username, $password)\r\n\r\nConnect-PowerBIServiceAccount -Credential $credential<\/pre>\n<ul>\n<li><strong>Service Principal<\/strong>: Use this method for non-interactive authentication.<\/li>\n<\/ul>\n<pre class=\"lang:css gutter:true start:1\">$clientId = \"your-client-id\"\r\n\r\n$clientSecret = \"your-client-secret\" | ConvertTo-SecureString -AsPlainText -Force\r\n\r\n$tenantId = \"your-tenant-id\"\r\n\r\n$credential = New-Object System.Management.Automation.PSCredential($clientId, $clientSecret)\r\n\r\nConnect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -Credential $credential<\/pre>\n<h3><strong>Step 2: Export Power BI Reports<\/strong><\/h3>\n<p>Once authenticated, you can export reports from a specific workspace. Here\u2019s how:<\/p>\n<p><strong>1. Retrieve the Workspace<\/strong>:<\/p>\n<p>$workspaceId = &#8220;your-workspace-id&#8221;<\/p>\n<p>$workspace = Get-PowerBIWorkspace -Id $workspaceId<\/p>\n<p><strong>2. Export Reports<\/strong>:<\/p>\n<pre class=\"lang:css gutter:true start:1\">Specify the export path and export the reports.\r\n\r\n$exportPath = \"C:\\Temp\\PowerBIExports\"\r\n\r\nif (!(Test-Path -Path $exportPath)) {\r\n\r\nNew-Item -ItemType Directory -Path $exportPath\r\n\r\n}\r\n\r\n\u00a0\r\n\r\n$reports = Get-PowerBIReport -WorkspaceId $workspace.Id\r\n\r\nforeach ($report in $reports) {\r\n\r\n$filePath = Join-Path -Path $exportPath -ChildPath \"$($report.Name).pbix\"\r\n\r\nExport-PowerBIReport -WorkspaceId $workspace.Id -ReportId $report.Id -OutFile $filePath\r\n\r\n}<\/pre>\n<p><strong>Step 3: Import Power BI Reports<\/strong><\/p>\n<p>After exporting the reports, you can import them into a new workspace.<\/p>\n<p><strong>1. Create a New Workspace<\/strong>:<\/p>\n<p>$newWorkspace = New-PowerBIWorkspace -Name &#8220;New Workspace&#8221;<\/p>\n<p><strong>2. Import Reports<\/strong>: Import the reports from the export path.<\/p>\n<pre class=\"lang:css gutter:true start:1\">$reportsToImport = Get-ChildItem -Path $exportPath -Filter \"*.pbix\"\r\n\r\nforeach ($reportFile in $reportsToImport) {\r\n\r\n$filePath = Join-Path -Path $exportPath -ChildPath $reportFile.Name\r\n\r\nNew-PowerBIReport -Path $filePath -Workspace $newWorkspace\r\n\r\n}<\/pre>\n<p><strong>Step 4: Update Dataset Parameters and Refresh<\/strong><\/p>\n<p>After importing the reports, you may need to update the dataset parameters and refresh the datasets.<\/p>\n<p><strong>1. Update Dataset Parameters<\/strong>:<\/p>\n<pre class=\"lang:css gutter:true start:1\">$datasetId = \"your-dataset-id\"\r\n\r\n$body = '{\r\n\r\n\"updateDetails\": [\r\n\r\n{\r\n\r\n\"name\": \"EnvironmentURL\",\r\n\r\n\"newValue\": \"your-new-value\"\r\n\r\n}\r\n\r\n]\r\n\r\n}'\r\n\r\nInvoke-PowerBIRestMethod -Url \"\/datasets\/$datasetId\/Default.UpdateParameters\" -Method Post -Body $body<\/pre>\n<p><strong>2. Refresh Dataset<\/strong>:<\/p>\n<p>Invoke-PowerBIRestMethod -Method Post -Url &#8220;groups\/$($newWorkspace.Id)\/datasets\/$datasetId\/refreshes&#8221;<\/p>\n<p><strong>Step 5: Update Data Source Credentials<\/strong> You must update the credentials if the imported reports rely on data sources.<\/p>\n<p><strong>1. Retrieve Data Sources<\/strong>:<\/p>\n<p>$datasources = Get-PowerBIDatasource -WorkspaceId $newWorkspace.Id -DatasetId $datasetId<\/p>\n<p><strong>2. Update Credentials<\/strong>:<\/p>\n<pre class=\"lang:css gutter:true start:1\">foreach ($datasource in $datasources) {\r\n\r\n$body = @{\r\n\r\n\"credentialDetails\" = @{\r\n\r\n\"credentialType\" = \"OAuth2\"\r\n\r\n\"encryptedConnection\" = \"Encrypted\"\r\n\r\n\"useCallerAADIdentity\" = $true\r\n\r\n}\r\n\r\n}\r\n\r\n$jsonBody = $body | ConvertTo-Json -Depth 5\r\n\r\nInvoke-PowerBIRestMethod -Url \"https:\/\/api.powerbi.com\/v1.0\/myorg\/gateways\/$($datasource.GatewayId)\/datasources\/$($datasource.DatasourceId)\" -Method PATCH -Body $jsonBody\r\n\r\n}<\/pre>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>By automating the export and import of Power BI reports using PowerShell, you can save time and reduce the risk of errors. This approach is particularly useful when managing multiple workspaces or environments. Whether you\u2019re migrating reports or setting up new environments, PowerShell provides a flexible and powerful way to streamline the process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Power BI has become an essential tool for business intelligence and reporting. However, managing Power BI reports across different environments or workspaces can be time-consuming and error-prone. PowerShell offers an efficient and reliable method to automate the export and import of Power BI reports. In this blog post, we\u2019ll walk through how to use PowerShell\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2025\/05\/automating-power-bi-report-export-and-import-using-powershell\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[45,2361],"tags":[1339,3159],"class_list":["post-41358","post","type-post","status-publish","format-standard","hentry","category-power-bi","category-technical","tag-power-bi","tag-powershell"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/41358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=41358"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/41358\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=41358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=41358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=41358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}