I'm fairly new to Powershell. I'm trying to build the body for an Invoke-PowerBIRestMethod to update parameters in the Power BI report. The format is
Invoke-PowerBIRestMethod -Url $url -Method Post -Body ("$body")
This is the body I've been using in my testing and it works, the parameter ServerName in the report is updated with the $NewServerName value:
$body = @"
{
"updateDetails": [
{
"name": "ServerName", "newValue": "$NewServerName"
}
]
}
"@
Requirements have changed and I need to make this more dynamic. Instead of hardcoding the parameter that needs to be updated the users will manually enter the ordered pair. And there could be more than one parameter that needs updating.
I'm not sure the best way to format the input parameters. I'm thinking they type param1:newvalue;param2:newvalue;param3:newvalue, etc. It needs to be as simple as possible since users will be entering this. Then in the Powershell script I'll parse that into the $body format.
And I'm not sure how to parse the input parameter into the $body format. The format will end up being like this:
$body = @"
{
"updateDetails": [
{
"name": "$param1", "newValue": "$newvalue1"
},
{
"name": "$param2", "newValue": "$newvalue2"
}
]
}
"@
Can anyone offer some suggestions?