Friday, October 23, 2020

PowerShell script to update Power BI Dataset parameters

In Power BI dataset or reports, parameters serve as a way to easily store and manage a value that can be changed after deployed. You could set up the parameters like database server name and database names inside Power BI solution and update through Power BI Settings as discussed before.

In this blog, we will use PowerShell to update the parameters. Here is the script to update the following two parameters on dataset named “MyReport” inside workspace named “My Workspace”. 

# Install-Module -Name MicrosoftPowerBIMgmt

# Connect to Power BI As admin

$User = "admin@mycompany.com"

$PW = "Password"

$SecPasswd = ConvertTo-SecureString $PW -AsPlainText -Force

$myCred = New-Object System.Management.Automation.PSCredential($User,$SecPasswd)

Connect-PowerBIServiceAccount -Credential $myCred


# Get Power BI Workspace ID

$WSID = Get-PowerBIWorkspace  -Scope Organization -Name 'My Workspace'| ForEach {$_.Id}


# Get Power BI Dataset ID

$DSIDMyReport = Get-PowerBIDataset -Scope Organization -WorkspaceId $WSIDAdmin | Where {$_.Name -eq "MyReport"} | ForEach {$_.Id}


# Construct Url with Dataset ID

$urlUpdateParams = "/datasets/" + $DSIDMyReport + "/Default.UpdateParameters"


# Update Parameters Body

$body = '{

  "updateDetails": [

    {

      "name": "DatabaseName",

      "newValue": "NewDBNamev"

    },

    {

      "name": "ServeName",

      "newValue": "myserver.database.windows.net"

    }

  ]

}'

$content = 'application/json'

# Update Dataset Parameters

Invoke-PowerBIRestMethod -Url $urlUpdateParams -Method Post -Body $body -ContentType $content

As enhancement, you could also use service principal as discussed in here to facilitate the login.

8 comments:

  1. ALANGOO is the first and only global exchange marketplace with a mission to provide a service for artists, artisan, designers, and artistic service providers with unique cultural backgrounds to present themselves to their diaspora. We are the platform where the artists that come from rich cultures, different backgrounds and all walks of life can sell their products and services worldwide. ALANGOO is spread from Los Angeles to London, to Istanbul and Yereva.

    Visit website: Persian name necklace

    ReplyDelete
  2. Thanks for sharing this information and keep updating us. This information is really helpful to me.
    Data analysis course in hyderabad

    ReplyDelete
  3. "Boost your career with expert salesforce admin training designed to master CRM management and automation. Learn practical skills, earn certification, and become a proficient Salesforce Administrator."

    ReplyDelete
  4. "Enhance your career with salesforce developer training mastering Apex, Visualforce, and Lightning components. Gain hands-on experience to become a certified Salesforce developer and excel in the CRM domain."

    ReplyDelete
  5. Learn Data Modeling to organize and optimize data efficiently—perfect for analysts, developers, and IT professionals. data modeling training

    ReplyDelete
  6. Get hands-on with Dell Boomi training: cloud integration, API management, and workflow automation made simple. boomi course

    ReplyDelete
  7. Become a skilled Java Full Stack Developer—master Java, Spring Boot, front-end frameworks, and real-world projects. java full stack developer course

    ReplyDelete
  8. Enhance your design career with UI/UX training: wireframing, prototyping, user research, and Figma skills. training ui ux

    ReplyDelete