Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops 如何以编程方式更新PowerBI数据集的Azure SQL数据源凭据?_Azure Devops_Powerbi_Powerbi Datasource - Fatal编程技术网

Azure devops 如何以编程方式更新PowerBI数据集的Azure SQL数据源凭据?

Azure devops 如何以编程方式更新PowerBI数据集的Azure SQL数据源凭据?,azure-devops,powerbi,powerbi-datasource,Azure Devops,Powerbi,Powerbi Datasource,我有一个Azure Devops进程,它使用服务原则从.pbix文件部署Power BI报告,并更新数据源以指向生产Azure SQL server 结果是部署了报表和数据集并更新了连接,但凭据为空(用户名和密码),因此为了使其可用,必须有人登录到Power BI服务,打开数据集并更新凭据,这意味着我们的CI/CD过程中涉及到手动步骤 我需要通过代码更新新数据源的源凭据的帮助,以便不需要此手动过程 任何建议都会大有帮助。谢谢。这里是一个示例PowerShell脚本,使用,它将在结尾添加注释,后

我有一个Azure Devops进程,它使用服务原则从.pbix文件部署Power BI报告,并更新数据源以指向生产Azure SQL server

结果是部署了报表和数据集并更新了连接,但凭据为空(用户名和密码),因此为了使其可用,必须有人登录到Power BI服务,打开数据集并更新凭据,这意味着我们的CI/CD过程中涉及到手动步骤

我需要通过代码更新新数据源的源凭据的帮助,以便不需要此手动过程


任何建议都会大有帮助。谢谢。

这里是一个示例PowerShell脚本,使用,它将在结尾添加注释,后面是几行(如果需要,请取消注释)。只需将顶部的x-es替换为实际值(工作区和数据集名称、应用程序ID等)


#填满这些###################################################
$tenantId=“xxxxxxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”#从Azure AD获取->属性(https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Properties)
$applictionId=“xxxxxxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”#从Azure AD获取应用程序(客户端)ID->应用程序注册(https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps)
$applicationSecret=“xxxxxxxxxxxxxxxxxx”#从应用程序的“证书和机密”部分创建它
$workspaceName=“xxxxxxxx”
$reportName=“xxxxxxxx”#实际上是数据集名称
$sqlUserName=“xxxxxxxx”
$sqlUserPassword=“xxxxxxxxx”
################################################################
导入模块MicrosoftPowerBIMgmt
$SecuredApplicationSecret=converttoSecureString-String$applicationSecret-AsPlainText-Force
$credential=新对象System.Management.Automation.PSCredential($applictionId,$SecuredApplicationSecret)
$sp=连接PowerBIServiceAccount-ServicePrincipal-Tenant$tenantId-Credential$Credential
$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($datasources中的datasource){
$gatewayId=$datasource.gatewayId
$datasourceId=$datasource.datasourceId
$datasourcepatchurl=“gateways/$gatewayId/datasources/$datasourceId”
写入主机“修补$datasourceId的凭据”
#修补数据源凭据的HTTP请求正文
$userNameJson=“{”“名称”“:”“用户名”“值”“:”“$sqlUserName”“}”
$passwordJson=“{”“名称”“:”“密码”“值”“:”“$sqlUserPassword”“}”
$patchBody=@{
“证书详情”=@{
凭据“=”{“credentialData”“:[$userNameJson$passwordJson]}
“凭证类型”=“基本”
“encryptedConnection”=“NotEncrypted”
“encryptionAlgorithm”=“无”
“privacyLevel”=“组织级”
}
}
#将正文内容转换为JSON
$patchBodyJson=converttoJSON-InputObject$patchBody-Depth 6-Compress
#执行修补程序操作以设置数据源凭据
调用PowerBIRestMethod-methodpatch-Url$datasourcepatchurl-Body$patchBodyJson
}
#$datasetRefreshUrl=“groups/$workspaceId/datasets/$datasetId/refreshes”
#写主机“刷新…”
#调用PowerBIRestMethod-Method Post-Url$datasetRefreshUrl

Hi Rohith,我可以知道您是否希望在Azure DevOps管道完成后更新源凭据吗?还是要在管道末尾使用PS脚本更新凭据?工作非常完美。。。谢谢你,安德烈。
<#

Patch the credentials of a published report/dataset, so it can be refreshed.

#>

# Fill these ###################################################
$tenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Get from Azure AD -> Properties (https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Properties)
$applictionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Get Application (client) ID from Azure AD -> App registrations (https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps)
$applicationSecret = "xxxxxxxxxxxxxxxx" # Create it from application's "Certificates & secrets" section
$workspaceName = "xxxxxxxx"
$reportName = "xxxxxxxx" # Actually it is dataset name
$sqlUserName = "xxxxxxxx"
$sqlUserPassword = "xxxxxxxxxx"
################################################################

Import-Module MicrosoftPowerBIMgmt

$SecuredApplicationSecret = ConvertTo-SecureString -String $applicationSecret -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($applictionId, $SecuredApplicationSecret)

$sp = Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $credential

$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