Public/Update-DatasetParameter.ps1

Function Update-DatasetParameter {
    <#
    .SYNOPSIS
        Updates a parameter value in a Microsoft Fabric dataset.
     
    .DESCRIPTION
        The Update-DatasetParameter function changes the value of a specified parameter
        in a Microsoft Fabric dataset by making a call to the Fabric API.
         
    .PARAMETER datasetId
        The ID of the dataset containing the parameter to update.
         
    .PARAMETER parameterName
        The name of the parameter to update.
         
    .PARAMETER parameterValue
        The new value to assign to the parameter.
         
    .EXAMPLE
        Update-DatasetParameter -datasetId "abc123-def456-ghi789" -parameterName "Region" -parameterValue "Europe"
        Updates the "Region" parameter to "Europe" in the specified dataset.
         
    .OUTPUTS
        Returns the API response from the update operation.
         
    .NOTES
        This function requires proper authentication to the Fabric API before use.
        Uses the Invoke-PbiApiRequest helper function to make the API call.
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]$datasetId,

        [Parameter(Mandatory)]
        [string]$parameterName,

        [Parameter(Mandatory)]
        [string]$parameterValue
    )
    
    $body = @{
        updateDetails = @(
            @{
                name = $parameterName
                newValue = $parameterValue
            }
        )
    }
    
    # Convert the body to JSON
    $bodyJson = $body | ConvertTo-Json

    Write-Log "Updating dataset parameter $parameterName to $parameterValue"
    $result = Invoke-PbiApiRequest -Uri "datasets/$datasetId/Default.UpdateParameters" -Method Post -Body $bodyJson
    return $result
}