可以在没有密码的情况下发布 powerbi 报告吗?
Possible to publish a powerbi report without password?
下午好,
我们的开发人员使用 PBI 创建了一些不错的报告,但问题是他们使用的是数据库 X。这些数据库仅包含开发数据。一旦他们要发布它,我们必须调整他们的报告以使用包含生产数据的数据库 Y。
开发人员是否可以发布他们的报告,将数据库从 X 更新到 Y,但不添加凭据?
通过这种方式,他们的报告将通过网关刷新,该网关将设置为使用 UID/PWD link 到 DB Y(用户无法访问)
谢谢:)
嗯,有人毕竟知道数据库 Y 的密码,对吧?为什么不在 Power BI Desktop 中打开报表,更改数据源,然后发布呢?但是有一些选项可以在数据源仍然是开发数据库(数据库 X)时重定向开发人员发布的报告。
首先,他们可以使用connection specific parameters 来定义数据源。然后,在发布之后,知道凭据的人更新参数值以将数据库重定向到生产数据库并输入凭据。
第二个不需要对报告进行任何更改。让您的开发人员发布它,然后使用 Power BI REST API to change the datasource and patch the credentials. This can be done for example with PowerShell using Power BI Management CmdLets。首先,以管理员身份启动 PowerShell 并通过执行以下脚本安装 CmdLets:
Install-Module MicrosoftPowerBIMgmt
如果您没有计算机的管理员权限,或者出于某些其他原因不想为所有用户安装这些,您可以只为当前用户安装它们:
Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser
你没有提到使用的是什么数据库。这很重要,因此在下面的示例中我将假设它是 SQL 服务器。更新前几行中的值以指向您的生产数据库和已发布的报告,然后执行脚本以更改数据源:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$datasetName = "The name of the report"
$sqlDatabaseServer = "Server name"
$sqlDatabaseName = "Database name"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $datasetName
$datasource = Get-PowerBIDatasource -WorkspaceId $workspace.Id -DatasetId $dataset.Id
# Construct url
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasourceUrl = "groups/$workspaceId/datasets/$datasetId/datasources"
# Call the REST API to get gateway Id, datasource Id and current connection details
$datasourcesResult = Invoke-PowerBIRestMethod -Method Get -Url $datasourceUrl | ConvertFrom-Json
# Parse the response
$datasource = $datasourcesResult.value[0]
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$sqlDatabaseServerCurrent = $datasource.connectionDetails.server
$sqlDatabaseNameCurrent = $datasource.connectionDetails.database
# Construct url for update
$datasourePatchUrl = "groups/$workspaceId/datasets/$datasetId/Default.UpdateDatasources"
# create HTTP request body to update datasource connection details
$postBody = @{
"updateDetails" = @(
@{
"connectionDetails" = @{
"server" = "$sqlDatabaseServer"
"database" = "$sqlDatabaseName"
}
"datasourceSelector" = @{
"datasourceType" = "Sql"
"connectionDetails" = @{
"server" = "$sqlDatabaseServerCurrent"
"database" = "$sqlDatabaseNameCurrent"
}
"gatewayId" = "$gatewayId"
"datasourceId" = "$datasourceId"
}
})
}
$postBodyJson = ConvertTo-Json -InputObject $postBody -Depth 6 -Compress
# Execute POST operation to update datasource connection details
Invoke-PowerBIRestMethod -Method Post -Url $datasourePatchUrl -Body $postBodyJson
# NOTE: dataset credentials must be reset after updating connection details
现在更新以下脚本开头的值并执行它以修补生产数据库的凭据:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$reportName = "The name of the report"
$sqlUserName = "user name"
$sqlUserPassword = "password"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $reportName
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasources = Get-PowerBIDatasource -WorkspaceId $workspaceId -DatasetId $datasetId
foreach($datasource in $datasources) {
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$datasourePatchUrl = "gateways/$gatewayId/datasources/$datasourceId"
Write-Host "Patching credentials for $datasourceId"
# HTTP request body to patch datasource credentials
$userNameJson = "{""name"":""username"",""value"":""$sqlUserName""}"
$passwordJson = "{""name"":""password"",""value"":""$sqlUserPassword""}"
$patchBody = @{
"credentialDetails" = @{
"credentials" = "{""credentialData"":[ $userNameJson, $passwordJson ]}"
"credentialType" = "Basic"
"encryptedConnection" = "NotEncrypted"
"encryptionAlgorithm" = "None"
"privacyLevel" = "Organizational"
}
}
# Convert body contents to JSON
$patchBodyJson = ConvertTo-Json -InputObject $patchBody -Depth 6 -Compress
# Execute PATCH operation to set datasource credentials
Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body $patchBodyJson
}
$datasetRefreshUrl = "groups/$workspaceId/datasets/$datasetId/refreshes"
Write-Host "Refreshing..."
Invoke-PowerBIRestMethod -Method Post -Url $datasetRefreshUrl
下午好,
我们的开发人员使用 PBI 创建了一些不错的报告,但问题是他们使用的是数据库 X。这些数据库仅包含开发数据。一旦他们要发布它,我们必须调整他们的报告以使用包含生产数据的数据库 Y。
开发人员是否可以发布他们的报告,将数据库从 X 更新到 Y,但不添加凭据? 通过这种方式,他们的报告将通过网关刷新,该网关将设置为使用 UID/PWD link 到 DB Y(用户无法访问)
谢谢:)
嗯,有人毕竟知道数据库 Y 的密码,对吧?为什么不在 Power BI Desktop 中打开报表,更改数据源,然后发布呢?但是有一些选项可以在数据源仍然是开发数据库(数据库 X)时重定向开发人员发布的报告。
首先,他们可以使用connection specific parameters 来定义数据源。然后,在发布之后,知道凭据的人更新参数值以将数据库重定向到生产数据库并输入凭据。
第二个不需要对报告进行任何更改。让您的开发人员发布它,然后使用 Power BI REST API to change the datasource and patch the credentials. This can be done for example with PowerShell using Power BI Management CmdLets。首先,以管理员身份启动 PowerShell 并通过执行以下脚本安装 CmdLets:
Install-Module MicrosoftPowerBIMgmt
如果您没有计算机的管理员权限,或者出于某些其他原因不想为所有用户安装这些,您可以只为当前用户安装它们:
Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser
你没有提到使用的是什么数据库。这很重要,因此在下面的示例中我将假设它是 SQL 服务器。更新前几行中的值以指向您的生产数据库和已发布的报告,然后执行脚本以更改数据源:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$datasetName = "The name of the report"
$sqlDatabaseServer = "Server name"
$sqlDatabaseName = "Database name"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $datasetName
$datasource = Get-PowerBIDatasource -WorkspaceId $workspace.Id -DatasetId $dataset.Id
# Construct url
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasourceUrl = "groups/$workspaceId/datasets/$datasetId/datasources"
# Call the REST API to get gateway Id, datasource Id and current connection details
$datasourcesResult = Invoke-PowerBIRestMethod -Method Get -Url $datasourceUrl | ConvertFrom-Json
# Parse the response
$datasource = $datasourcesResult.value[0]
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$sqlDatabaseServerCurrent = $datasource.connectionDetails.server
$sqlDatabaseNameCurrent = $datasource.connectionDetails.database
# Construct url for update
$datasourePatchUrl = "groups/$workspaceId/datasets/$datasetId/Default.UpdateDatasources"
# create HTTP request body to update datasource connection details
$postBody = @{
"updateDetails" = @(
@{
"connectionDetails" = @{
"server" = "$sqlDatabaseServer"
"database" = "$sqlDatabaseName"
}
"datasourceSelector" = @{
"datasourceType" = "Sql"
"connectionDetails" = @{
"server" = "$sqlDatabaseServerCurrent"
"database" = "$sqlDatabaseNameCurrent"
}
"gatewayId" = "$gatewayId"
"datasourceId" = "$datasourceId"
}
})
}
$postBodyJson = ConvertTo-Json -InputObject $postBody -Depth 6 -Compress
# Execute POST operation to update datasource connection details
Invoke-PowerBIRestMethod -Method Post -Url $datasourePatchUrl -Body $postBodyJson
# NOTE: dataset credentials must be reset after updating connection details
现在更新以下脚本开头的值并执行它以修补生产数据库的凭据:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$reportName = "The name of the report"
$sqlUserName = "user name"
$sqlUserPassword = "password"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $reportName
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasources = Get-PowerBIDatasource -WorkspaceId $workspaceId -DatasetId $datasetId
foreach($datasource in $datasources) {
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$datasourePatchUrl = "gateways/$gatewayId/datasources/$datasourceId"
Write-Host "Patching credentials for $datasourceId"
# HTTP request body to patch datasource credentials
$userNameJson = "{""name"":""username"",""value"":""$sqlUserName""}"
$passwordJson = "{""name"":""password"",""value"":""$sqlUserPassword""}"
$patchBody = @{
"credentialDetails" = @{
"credentials" = "{""credentialData"":[ $userNameJson, $passwordJson ]}"
"credentialType" = "Basic"
"encryptedConnection" = "NotEncrypted"
"encryptionAlgorithm" = "None"
"privacyLevel" = "Organizational"
}
}
# Convert body contents to JSON
$patchBodyJson = ConvertTo-Json -InputObject $patchBody -Depth 6 -Compress
# Execute PATCH operation to set datasource credentials
Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body $patchBodyJson
}
$datasetRefreshUrl = "groups/$workspaceId/datasets/$datasetId/refreshes"
Write-Host "Refreshing..."
Invoke-PowerBIRestMethod -Method Post -Url $datasetRefreshUrl