Tag: aether

  • Updating PowerBI reports with PowerShell

    Updating PowerBI reports with PowerShell

    So this is probably the last PowerShell script for the moment. But this is where it gets interesting, we can now combine some of those scripts to make a quick and easy way of updating PowerBI reports with PowerShell.

    If you have the requirement where you have multiple instances of the same report across the same or different workspaces this script is for you!

    I had that requirement as part of Prism and again as things scaled up, this became a huge time saver. It also removed the potential of human error when moving parameters around, uploading to the correct workspace.

    Similar to the uploading new report script in my previous post, this one will pick up a pbix file then scan over your workspaces (based on when filters you apply). When it finds reports that again match your criteria, it will take a copy of the current parameters, update the pbix file and then load the parameters back in.

    Meaning, you have a PowerBI report uploaded to the service with your latest changes from a single source file, the parameters all remain the same as before, the script then refreshes to pull in the data based on those parameters and all good to go!

    As part of version control, I currently use a parameter to record the current version of my reports. This adds an extra benefit as I can then use this script to check if the reports are already on the expected version. Just in case the script is interrupted, we need to deploy on stages.

    I then add in the new version number as part of the script and this becomes a great way to track report versions when updating PowerBI reports with PowerShell.

    How it works?

    • Connects to Power BI Service using Connect-PowerBIServiceAccount.
    • Retrieves all Power BI workspaces using Get-PowerBIWorkspace.
    • Loops through each workspace and identifies reports whose names start with “AETHER”.
    • For each report:
    • Retrieves the dataset parameters.
    • Updates the first parameter’s value to a specified version if it doesn’t already match.
    • Overwrites the report in the workspace using a specified PBIX file ($FilePath).
    • Takes over the dataset to ensure permissions are set correctly.
    • Updates the dataset parameters.
    • Triggers a dataset refresh.

    Key things you can change

    • $DeployVer: The new deployment version to update the first parameter to (e.g., “2025Q1”).
    • $FilePath: The path to the PBIX file used for updating reports.
    • Parameter 0 is assumed to represent a version parameter (e.g., “2025Q1”)

    https://github.com/AetherAdv/powerbi_powershell_updatereports/upload/main

    # Connect to Power BI Service Account
    Connect-PowerBIServiceAccount
    
    # Set the deployment version to be used for updating parameters
    $DeployVer = "2025Q1"
    
    # Define the path to the PBIX file to be used for report updates
    $FilePath = "C:\Temp\myreport.pbix"
    
    # Define the conflict action for updating reports (e.g., Create or Overwrite existing reports)
    $Conflict = "CreateOrOverwrite"
    
    # Retrieve all Power BI workspaces
    $workspaces = Get-PowerBIWorkspace -All
    
    # Loop through each workspace
    foreach ($workspace in $workspaces) {
    
        # Get all reports in the current workspace with names starting with "AETHER"
        $Reportlist = Get-PowerBIReport -WorkspaceId $workspace.Id | Where-Object { $_.Name -like 'AETHER*' }
    
        # Check if any reports were found in the workspace
        if ($Reportlist) {
            Write-Host "Workspace: $($workspace.Name)" # Log the workspace name
    
            # Loop through each report in the report list
            foreach ($Report in $Reportlist) {
                Write-Host "  Report: $($Report.Name)" # Log the report name
    
                $JsonString = $null # Initialize JSON string variable
    
                # Retrieve the parameters of the dataset associated with the report
                $ParametersJsonString = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/parameters" -Method Get
                $Parameters = (ConvertFrom-Json $ParametersJsonString).value # Convert JSON response to PowerShell object
    
                # Initialize an empty array to hold parameter updates
                $UpdateParameterList = @()
    
                # Loop through each parameter and prepare the update list
                foreach ($Parameter in $Parameters) {
                    $UpdateParameterList += @{ "name" = $Parameter.name; "newValue" = $Parameter.currentValue }
                }
    
                # Check if there are any parameters to update
                if ($UpdateParameterList.Count -gt 0) {
                    # Get the current value of the first parameter
                    $currentparam = $UpdateParameterList[0].newValue
    
                    Write-Host "    Current Parameter 0 Value: $currentparam" # Log the current parameter value
    
                    # Check if the current parameter value matches the deployment version
                    if ($currentparam -ne $DeployVer) {
                        Write-Host "Version does not match. Updating..." # Log the update action
    
                        # Update the first parameter to the new deployment version
                        $UpdateParameterList[0].newValue = $DeployVer
                    }
                    else {
                        Write-Host "Version already matches. Skipping update." # Log if no update is needed
                    }
    
                    # Prepare the JSON payload for updating parameters
                    $JsonBase = @{ "updateDetails" = $UpdateParameterList }
                    $JsonString = $JsonBase | ConvertTo-Json
    
                    # Define the report name
                    $ReportName = $Report.Name
    
                    # Update the existing report in the workspace
                    New-PowerBIReport -Path $FilePath -Name $ReportName -WorkspaceId $workspace.Id -ConflictAction $Conflict
    
                    # Take over the dataset to ensure permissions are set correctly
                    Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.TakeOver" -Method Post
    
                    # Update the parameters of the dataset
                    Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.UpdateParameters" -Method Post -Body $JsonString
    
                    # Pause for 5 seconds to avoid API rate limits
                    Start-Sleep -Seconds 5
    
                    # Trigger a dataset refresh
                    Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/refreshes" -Method Post
                    Write-Host "Refresh started." # Log the refresh action
                }
                else {
                    Write-Host "No parameters found for this dataset." # Log if no parameters are found
                }
            }
        } else {
            Write-Host "No reports found in workspace: $($workspace.Name)" # Log if no reports are found in the workspace
        }
    }
    
    # Log the completion of the script
    Write-Host "Script completed."
  • My Path to Product: PowerBI & Prism

    My Path to Product: PowerBI & Prism

    Yes, that is Sonic the Hedgehog (those who know me will know I’m a bit of a fan). But more than just nostalgia, this was one of the last 3D models I created—somewhere between 10 and 15 years ago—right before I met my now wife and started a family. Oddly enough, it’s also where the mindset that helped me build Prism really began. This is my path to product: PowerBI & Prism.

    Back then, I used to spend hours tweaking and changing all the aspects big and small of the design, lighting, textures and just about everything involved in my 3D work (I actually did Games Development at University).

    I have always been into tech so had built myself a powerhouse of a PC to work on these things.

    As I moved into working for Trustmarque, whilst I was still very tech focused and now involved in the world of licensing, I still had that desire to create.

    I had worked with Microsoft products most of my life in some form or another and at this point understood pretty much all involved to a certain degree with IT infrastructure.

    A few years in, I was introduced to Microsoft PowerBI, a product that I had never touched before but one that turned out to be exactly what I needed.

    I’ve been told several times I have a bit of a superpower: the ability to learn insanely fast, especially if I can then go build something with what I’ve learned

    I never took any formal training for PowerBI as I learnt best by doing. Some of the fantastic content creators out there, a lot of who I now engage with were the perfect resource to understand visuals, DAX, measures, everything. I went through tonnes of content and then applied what I already knew.

    PowerBI became that evolution of creating 3D renders of Sonic.

    I started collecting data, building dashboards, experimenting with design and UX, and exploring new ways to interact with data—many of which were still rare or new at the time.

    Eventually, it turned into a product. One I was passionate about, not because I was told to build it, but because I wanted to. (I even loaded up Photoshop and made the logo).

    At this point I had no idea how successful Prism would become.

    There were other tools on the market—many built by much bigger dev teams using more conventional approaches. But Power BI gave me an edge: speed and adaptability.

    Making a product using PowerBI as a base meant I could adapt to changes in the IT market (and there are a lot) very quickly.

    I could respond to customer feedback in near real-time. I could change visuals, metrics, or layouts in hours—not weeks.

    Now, I’m a Lead Product Manager at Trustmarque, Prism is used by customers around the world, Trustmarque has built services around Prism to great success and the product receives nothing but praise.

    It’s not one I ever expected, but product management with Power BI turned out to be my ideal job.

    Sure, it has its stresses. But every day, I get to build, come up with new ideas, meet new exciting people, and help others see more clearly—through data.

    So, the original thought for this blog post. what would I say to someone just starting out?

    • Find data that means something to you. Maybe you’ve worked with it before, or maybe it’s just something that grabs your attention.
    • Just build. It won’t be perfect. It shouldn’t be. But each dashboard you tweak, each visual you redesign, will teach you something new.
    • Design matters. A great UI can make your dashboard. Play with colour palettes—Coolors is a great resource for that.
    • Think scale early. Whether it’s your data source, Power BI capacity, or your deployment strategy—plan ahead.
    • Consider Power BI Embedded if you’re heading into product. It opens up possibilities beyond licensing and lets you create apps around your reports.
    • Adapt fast. This is Power BI’s secret weapon in product. Use it.
    • Document it. I’m now using my Aether platform and blog posts to share lessons I’ve learned along the way. You should too!

    If you’re interested in scaling, automation, and pushing updates across environments, I’ve written a few PowerShell posts that might help too.

    Thanks for reading—and if you’re just starting out, enjoy it. I started with Sonic. You can start wherever you like.

    Bonus!

    And just in case you were interested here were a couple of others out of what seems loads! Seems a long time ago now!

  • Uploading new reports with PowerShell

    Uploading new reports with PowerShell

    At this point you may be starting to wonder how many PowerShell scripts I have for working with PowerBI, turns out quite a few! Uploading new reports with PowerShell is the latest one!

    As Prism grew I was looking at more workspaces and more reports, and so I turned to what I knew best at the time, PowerShell. Whilst going into PBI desktop, ensuring the data was loaded up then publishing to the PowerBI service doesn’t take a huge amount of time individually, but when building a product I needed much greater flexibility.

    So what this latest script does is solve that exact problem.

    The PBIX files I have are all loaded into source control but have a copy ready that is synced via VsCode. This script will pick up that file and upload it to the PowerBI workspace as required. (Even creating the PowerBI workspace and adding permissions at the same time if needed!)

    In my case and something you may be interested in as well, I then combined this script with a couple of the others I have already posted about. Adding parameters and setting refresh times. At this point you can automate the whole thing end to end!

    How does it work?

    This script whilst looks simple, will do quite a few things!

    Firstly, you need to provide a name for your workspace and a name for your report. These are going to be what the script uses, regardless of what your PBIX file is named already.

    If using this part of the code, you will also need to supply your capacity ID. This is so the workspace can then link up with your premium / embedded / fabric etc capacity. Note this will require you to have a level of admin permissions in your organisation if you want to do this automated.

    Once it has set those, it will add a new user (usually best to have more than just yourself as an admin on these things). In this example ive added a user, you can add groups , distribution lists all sorts. Prism for example, we have support teams as group who get applied to new workspaces.

    Lastly it will upload the PBIX file you specified, name it how you wanted all ready to go!

    The Script

    Connects to the PowerBI service Account

    Uses the parameters you have set to:

    Create a PowerBI workspace

    Add it to the specified capacity

    Adds a new admin user

    Add the PowerBI report

    Like I say, combine this with the other PowerShell scripts I have posted about uploading new reports with PowerShell will then go even further! Especially if you are using PowerBI as part of a product or simply dealing with many workspaces and reports.

    https://github.com/AetherAdv/powerbi_powershell_addnew

    # Ensure Power BI module is installed
    Import-Module MicrosoftPowerBIMgmt
    
    # Connect to Power BI (if not already connected)
    Connect-PowerBIServiceAccount
    
    # Define conflict action
    $Conflict = "CreateOrOverwrite"
    
    # Define Capacity ID
    $CapacityId = "00000000-0000-0000-0000-000000000000"  # Replace with your capacity ID
    
    # Define workspace details
    $WorkspaceName = "AETHER - MyNewWorkspace"
    
    # Define report details
    $ReportName = "AETHER - MyReport"
    
    # Define PBIX file path
    $DeployPath = "C:\Temp\myreport.pbix"
    
    # Create the workspace
    $Workspace = New-PowerBIWorkspace -Name $WorkspaceName
    
    # Wait a few seconds for workspace creation - just incase it needs time to be accessible
    Start-Sleep -Seconds 5
    
    # Assign the workspace to a Power BI Premium capacity - Not this will require some additional licence and access considerations to do with commands!
    Set-PowerBIWorkspace -Id $Workspace.Id -CapacityId $CapacityId -Scope Organization
    
    # Add a user as an admin
    Add-PowerBIWorkspaceUser -Id $Workspace.Id -UserPrincipalName "user@jamesmm.com" -AccessRight Admin
    
    # Publish the Power BI report
    New-PowerBIReport -Path $DeployPath -Name $ReportName -WorkspaceId $Workspace.Id -ConflictAction $Conflict