power bi 数据刷新_如何管理Power BI数据集刷新失败

power bi 数据刷新

As I covered in a previous post How to connect to (and query) Power BI and Azure using PowerShell, Power BI can be difficult to manage and administer, unlike on-premises BI solutions. One such concern that will often require quick action is the failure of a dataset refresh.

正如我在上一篇文章“ 如何使用PowerShell连接到(和查询)Power BI和Azure中所介绍的”中所述,与本地BI解决方案不同,Power BI可能难以管理。 通常需要快速采取行动的此类关注之一是数据集刷新失败。

If your reports and dashboards all rely on live connection or DirectQuery data sources like Azure SQL Database, Azure SQL Data Warehouse or SQL Server Analysis Services (on-premises or in Azure) then you won’t have to worry about dataset refreshes and this post will just be some interesting reading.

如果您的报表和仪表板都依赖实时连接或DirectQuery数据源(例如Azure SQL数据库,Azure SQL数据仓库或SQL Server Analysis Services)(本地或在Azure中),那么您就不必担心数据集刷新和这篇文章。将会是一些有趣的阅读。

Chances are, that you probably have at least one report that relies on an on-premises database or file source and you need to schedule it to refresh regularly to get up to date data. It’s in managing this functionality that the current offering within Power BI falls short, hopefully not for long with the rate updates are coming!

可能是,您可能至少有一个依赖于本地数据库或文件源的报告,并且需要安排它定期刷新以获取最新数据。 正是在管理此功能中,Power BI中的当前产品不足,希望随着速率更新的到来不会太久!

内置故障通知 (Built-in failure notifications)

Power BI has a method to notify you of a failed dataset, which is great. You obviously want to know when data wasn’t updated & you probably want to notify users or customers too. You may have received such an alert already. They look something like this:

Power BI有一种方法可以通知您失败的数据集,这很棒。 您显然想知道什么时候数据没有更新,您也可能想通知用户或客户。 您可能已经收到了这样的警报。 他们看起来像这样:

That’s a great first step but there is a great deal further we need to go to satisfy my inner Administrator.

这是迈出的重要第一步,但我们还需要做很多工作才能使我的内部管理员满意。

谁拥有这个! (Who owns this!?)

You may have noticed the little checkbox near the bottom of each dataset settings page that lets you turn these failure notifications on.

您可能已经注意到每个数据集设置页面底部附近的小复选框,可用于打开这些故障通知。

The issue here is that there is no CC for a wider admin user or group. This notification will only email the current dataset owner in the event of a failure. Depending on your process for deploying content to Power BI or how users interact with it, this could be an analyst, a sales manager, a developer or indeed, the person who would be able to source & fix the issue.

这里的问题是没有CC用于更广泛的管理员用户或组。 如果发生故障,此通知将仅通过电子邮件发送给当前数据集所有者。 根据您将内容部署到Power BI的过程或用户与之交互的方式,这可能是分析师,销售经理,开发人员,或者实际上是能够找到并解决问题的人员。

Even with processes in place to “hand over” dataset ownership to a single administrator account, there will always be fluidity in where these notifications get sent, thus delaying the resolution of any issues that arise

即使有了将数据集所有权“移交给”一个管理员帐户的流程,发送这些通知的位置始终存在流动性,从而延迟了出现的任何问题的解决

但是怎么了!! (But WHAT went wrong!?)

Oops, something went wrong! You’ve received your failure notification; now let’s check the email to see what happened.

哎呀!出事了! 您已收到失败通知; 现在,让我们检查电子邮件以了解发生了什么。

Referring to the email excerpt above, we can see the dataset name & its next refresh time. Great, but what if you have the same dataset across several workspaces, maybe in a DEV, QA, PROD scenario?

参考上面的电子邮件摘录,我们可以看到数据集名称及其下一次刷新时间。 很好,但是如果您在多个工作空间中拥有相同的数据集,那可能是在DEV,QA,PROD场景中怎么办?

There’s no link to the failing dataset or the parent workspace. At the time of writing this, the Learn More link also hits a 404.

没有链接到失败的数据集或父工作区。 在撰写本文时,“ 了解更多”链接也会显示404。

Here is a good alternative page for troubleshooting dataset refresh issues: Troubleshooting Refresh Scenarios

这是解决数据集刷新问题的一个不错的替代页面: 刷新方案疑难解答

PowerShell警报 (PowerShell alerting)

Building on the API interactions within PowerShell from my previous blog posts I wanted to create my own dataset failure monitor. It’s not perfect but it will get me a lot more information than I get from the built-in functionality, and allow me to respond quicker too.

在我以前的博客文章中基于PowerShell中的API交互基础上,我想创建自己的数据集故障监视器。 这不是完美的方法,但是它将为我提供比内置功能更多的信息,并且也使我能够更快地做出响应。

I started by splitting out two reusable components of this monitor script to functions. The authentication & the notification.

我首先将此监视脚本的两个可重用组件分解为多个函数。 身份验证和通知。

I reference these in the main script but I plan on expanding and building these into a module in the future. Keep an eye on my GitHub. For now, save them with their function names in the same folder as the monitor script and you’re ready to go.

我在主脚本中引用了它们,但我计划将来将它们扩展并构建到模块中。 密切关注我的GitHub 。 现在,将它们及其函数名称保存在与监视脚本相同的文件夹中,即可开始使用。

Get-PBIAuthTokenUnattended (Get-PBIAuthTokenUnattended)

This first one is the authentication function. It enables unattended authentication into Azure with the use of an encrypted text file for your account’s password. The main blocker you will have with this function is the requirement for a Power BI “app”. If you already have your ClientID & Client Secret to hand, you can skip Steps 1 & 2.

第一个是身份验证功能。 通过使用加密的文本文件作为帐户密码,可以启用无人参与的身份验证到Azure。 使用此功能的主要功能是Power BI“应用程序”的要求。 如果您已经拥有ClientID和Client Secret,则可以跳过步骤1和2。

  1. The Power BI app can be created from the Power BI app registration page. You do not need to be an Azure or Power BI admin to do so which is great. Make sure you choose the Server-side Web App type, which will generate both a ClientID and a Client_Secret. The ClientID can be retrieved from Azure if needed but if you don’t make note of the Client_Secret when you create the app, it’s gone. Start again. You will want to at least tick all the options under the Dataset API section for permissions.

    可以从Power BI应用程序注册页面创建Power BI应用程序 。 您无需成为Azure或Power BI管理员即可,这很棒。 确保选择服务器端Web应用程序类型,它将同时生成ClientID和Client_Secret。 可以根据需要从Azure检索ClientID,但是如果在创建应用程序时未记下Client_Secret,则该ID将消失。 重新开始。 您将至少要勾选“数据集API”部分下的所有选项以获取权限。

    power bi 数据刷新_如何管理Power BI数据集刷新失败_第1张图片

  2. The next thing you will have to do is log in to Azure using the account you created the app with to Grant Permissions, allowing users to authenticate with the app. This can be found under the App Registrations section shown below.

    接下来要做的是使用创建应用程序的帐户使用“授予权限”登录Azure,以允许用户通过应用程序进行身份验证。 可以在下面显示的“ 应用程序注册”部分中找到。

    power bi 数据刷新_如何管理Power BI数据集刷新失败_第2张图片

    • Log in to Microsoft Azure as an administrator. In the Microsoft Azure portal, click Azure Active Directory. Under Manage, click Properties. The tenant ID is shown in the Directory ID box.

      以管理员身份登录到Microsoft Azure。 在Microsoft Azure门户中,单击“ Azure Active Directory”。 在管理下,单击属性。 租户ID显示在“目录ID”框中。
    • Using this command, it will query Azure anonymously (thanks to user5347643 on StackOverflow):
      $tenantID = (Invoke-WebRequest -UseBasicParsing  https://login.windows.net/sqlglasgow.onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]
      
    • 使用此命令,它将匿名查询Azure(由于StackOverflow上的user5347643 ):
Note: I added the 注意:我添加了 -UseBasicParsing parameter which negates the need for IE to be installed/configured locally. -UseBasicParsing参数,它不需要在本地安装/配置IE。
<#
.SYNOPSIS
Authenticate against the Power BI API
 
.DESCRIPTION
This is an unattended authentication function. 
# Prerequisites
#-------------------------------------------------------------------------------
# Client ID & Client Secret can be obtained by creating a Power BI app:
# https://dev.powerbi.com/apps
# App Type: Web App / API
#-------------------------------------------------------------------------------
 
.PARAMETER userName
This is the user that will connect to Power BI. The datasets & groups that are returned
are restricted by the user's permissions
 
.PARAMETER tenantID
#----------------------------------------
# To find your Office 365 tenant ID in the Azure AD portal
# - Login to Microsoft Azure as an administrator.
# - In the Microsoft Azure portal, click Azure Active Directory.
# - Under Manage, click Properties. The tenant ID is shown in the Directory ID box.
 
.PARAMETER clientId
This is the ID generated by the Power BI App created above. It can also be found from
within Azure
 
.PARAMETER client_secret
This is also generated when the Power BI App is created & must be noted as it is
irretrievable once you leave the page
 
.PARAMETER mailServer
Your mail server
 
.PARAMETER mailFrom
Your selected FROM address to send error or notification emails
 
.PARAMETER mailTo
The recipient email address or addresses (separated by semicolons) that will receive
error and notification emails
 
.EXAMPLE
$authtoken = Get-PBIAuthTokenUnattended -userName [email protected] -tenantID "85b7f285-XXXX-XXXX-XXXX-ec7116aa9ef5" -clientId "f40daa92-XXXX-XXXX-XXXX-7e027fe03e2e" -client_secret "5bM2KeZl2nVXXXXXXXXXXXXi6IYVPOt8lAtPwXXXXXX=""
#>
function Get-PBIAuthTokenUnattended
{
 
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]    
        [string]
        $userName = "$(Read-Host 'Power BI Account')",
        
        [string]
        $tenantID,
        
        [Parameter(Mandatory=$true)]  
        [string]
        $clientId,
        
        [Parameter(Mandatory=$true)]  
        [string]
        $client_secret
    )
 
    begin {
        #Include email function
        . ".\Invoke-AlertEmail.ps1"
 
        if($tenantID.Length -lt 36)
        {
            Write-Verbose 'Split the string on the username to get the Domain'
            $tenantDomain = $userName.Split("@")[1]
            Write-Verbose 'Querying Azure anonymously (this may not work for ALL tenant domains. Eg. Those that use .onmicrosoft.com)'
            $tenantID = (Invoke-WebRequest -UseBasicParsing https://login.windows.net/$($tenantDomain)/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]
        }
 
        $pbiAuthorityUrl = "https://login.windows.net/$tenantID/oauth2/token"
        $pbiResourceUrl = "https://analysis.windows.net/powerbi/api"
 
        Write-Verbose 'Test if ADAL module is installed & install if DLL not found'
        $moduleName = 'Microsoft.ADAL.PowerShell'        
        Try
        {
            if (Get-Module -ListAvailable -Name $moduleName)
            {
                Import-Module -Name $moduleName -ErrorAction SilentlyContinue
            }        
            else
            {
                Install-Module -Name $moduleName -ErrorAction SilentlyContinue
            }
        }
        Catch
        {
            throw '$moduleName module is not installed and could not be added'
        }
 
        Write-Verbose 'Get Username from encrypted text file'    
        $path = (Resolve-Path .\).Path
        #Grab current user as encrypted file is tagged with who encrypted it	
        $user = $env:UserName	
        $file = ($userName + "_cred_by_$($user).txt")
        Write-Verbose 'Testing if credential file exists & create if not'
        if(Test-Path $file)
        {
            $Pass = Get-Content ($path + '\' + $file) | ConvertTo-SecureString
        }
        else{
            Write-Host 'Encrypted Credential file not found. Creating new file.'
		    Read-Host -Prompt "Please enter Password for $userName" -AsSecureString | ConvertFrom-SecureString | Out-File "$($path)\$($userName)_cred_by_$($user).txt"
            Write-Verbose 'Encrypted file created'
            $Pass = Get-Content ($path + '\' + $file) | ConvertTo-SecureString
        }
    }
    Process{
        
        try {
            #Pull password from secure string
            $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Pass)
            $textPass = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
            
            Write-Verbose 'Authenticating to Azure/PBI'
            $authBody = @{
                    'resource'=$pbiResourceUrl
                    'client_id'=$clientId        
                    'grant_type'="password"
                    'username'=$userName
                    'password'= $textPass
                    'scope'="openid"
                    'client_secret'=$client_secret
                }
            #Clear password variable immediately after use
            $textPass = $null            
            $auth = Invoke-RestMethod -Uri $pbiAuthorityUrl -Body $authBody -Method POST -Verbose
            #Clear auth array immediately after use
            $authBody = $null            
        }
        catch {
            Write-Error 'Authentication or Connection failure.'
            $script = $MyInvocation.MyCommand.Name	
            $subject = "$script Error: Authentication Failure"
            $htmlContent = $_.Exception.Message
            Invoke-AlertEmail -title $script -htmlContent $htmlContent -subject $subject -alertColour "#FF5733"  
            throw $_            
        }
        Write-Verbose 'Authentication token retrieved'
        return $auth
    }
}

调用警报电子邮件 (Invoke-AlertEmail)

The notification function basically builds up a generic HTML email that I intend on using for more PowerShell scripts & error handling, so feel free to adjust as you wish. I replicated the style of the Power BI failure notifications as a quick, clean solution. There’s even a parameter to pass a hex colour to this function, so you can colour code your emails! If you need to authenticate to your mail server, we can use a similar method to the authentication function, by using an encrypted text file. I have included this and added a switch (-auth) when calling the script to enable that functionality.

通知功能基本上可以建立通用HTML电子邮件,我打算将其用于更多的PowerShell脚本和错误处理,因此可以随意调整。 我将Power BI故障通知的样式复制为一种快速,干净的解决方案。 甚至还有一个参数可以将十六进制颜色传递给此函数,因此您可以对电子邮件进行颜色编码! 如果您需要对邮件服务器进行身份验证,我们可以通过使用加密的文本文件来使用与身份验证功能类似的方法。 我已经包括了它,并在调用脚本以启用该功能时添加了一个开关(-auth)。

<#
.SYNOPSIS
This is an email function that builds an HTML email to be used for script outputs and error handling
 
.DESCRIPTION
Long description
 
.PARAMETER subject
This is the email subject and is a mandatory parameter.
 
.PARAMETER title
This is the title of the email that will be included in the top, color coded panel. It should contain the source script name or purpose
 
.PARAMETER htmlContent
This is the main body of the email and should be a string, constructed in the calling script to display the required information in the email
 
.PARAMETER companyLogo
This is a logo that will show above the title section of the email, for organization branding
 
.PARAMETER companyLogoAlt
Alternative text for the logo
 
.PARAMETER team
This is used in the email signature as the source "team or user" for the email
 
.PARAMETER alertColour
This is a hex color to color code the email title section
 
.PARAMETER mailServer
Mail server to be used for distribution.
 
.PARAMETER mailFrom
Email address to be displayed as the sender
 
.PARAMETER mailTo
Recipient(s) for the email
 
.EXAMPLE
Invoke-AlertEmail -subject "Test subject" -title "Email Title" -htmlContent "Test content
More content"
  .NOTES General notes #> function Invoke-AlertEmail {       [CmdletBinding()]     param(         [Parameter(Mandatory=$true)]         [string]         $subject,               [Parameter(Mandatory=$true)]         [string]         $title,           [Parameter(Mandatory=$true)]         [String]         $htmlContent,           [string]         $companyLogo = 'https://i0.wp.com/sqlglasgow.co.uk/wp-content/uploads/2017/10/sql-glasgow-logo-full-TEMP_SQL-Glasgow-copy-e1508254573114.png?fit=700%2C140',           [string]         $companyLogoAlt = 'CraigPorteous.com BI Team Logo',           [string]         $team = 'CraigPorteous.com BI Team',           [string]         $alertColour = 'D3D3D3',           #Flag for Auth required for email server         [switch]         $auth,           #Set Mail settings for error handling         [string]         $mailServer = "smtp.office365.com",           [string]         $mailFrom = "[email protected]",           [string]         $mailTo = "[email protected]"             )       begin{         Write-Verbose 'Checking supplied Hex colour code'         if($alertColour -Match '^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')         {             #Perfect match             Write-Verbose 'Hex colour code Accepted'         }         elseif($alertColour -Match '^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$') {             #Add # Prefix             $alertColour = "#$($alertColour)"         }         else{             Write-Error 'Invalid HEX Colour code provided'             $script = $MyInvocation.MyCommand.Name             $subject = "$script Error: Invalid Hex Colour used"             $htmlContent = "HEX used in script: $($alertColour)"             Invoke-AlertEmail -title $script -htmlContent $htmlContent -subject $subject -alertColour "#FF5733"               throw         }           if ($auth) {             Write-Verbose 'Retrieving Credential component for mail servers that require Auth'             #----------------------------------------------------------------------             Write-Verbose 'Get Username from encrypted text file'             $path = (Resolve-Path .\).Path                          #Grab current user so encrypted file is tagged with who encrypted it             $user = $env:UserName             $file = ($mailFrom + "_cred_by_$($user).txt")             Write-Verbose 'Testing if credential file exists & create if not'             if(Test-Path $file)             {                 $Pass = Get-Content ($path + '\' + $file) | ConvertTo-SecureString             }             else{                 Write-Host "Encrypted Credential file not found. Creating new file."                 Read-Host -Prompt "Please enter Password for $mailFrom" -AsSecureString | ConvertFrom-SecureString | Out-File "$($path)\$($mailFrom)_cred_by_$($user).txt"                 Write-Verbose 'Encrypted file created'                 $Pass = Get-Content ($path + '\' + $file) | ConvertTo-SecureString             }             $Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $mailFrom, $Pass             #----------------------------------------------------------------------         }     }     process{           Write-Verbose 'Build email HTML header'         $htmlHeader = ""           Write-Verbose 'Build email HTML Body'         $htmlBody = "                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    


$($title)

                                            
$($htmlContent)
                                        
                                            
Thanks,
                                            
$($team)
                                        
  
                        
"
                 $htmlEmail = ConvertTo-Html -Head $htmlHeader -Body $htmlBody | Out-String                    try {                         if($auth)             {                 Write-Verbose 'Send Mail using authentication & SSL'                 send-mailmessage -SmtpServer $mailServer -From $mailFrom -To $mailTo -Subject $subject -BodyAsHtml -Body $htmlEmail -Credential $Cred -UseSsl -Port "587"                                       }             else             {                 Write-Verbose 'Send Mail'                 send-mailmessage -SmtpServer $mailServer -From $mailFrom -To $mailTo -Subject $subject -BodyAsHtml -Body $htmlEmail                       }                     }         catch {             #Catch an issue             throw $_         }     } }

PowerBI_Dataset_Alerting (PowerBI_Dataset_Alerting)

Finally, here is the actual monitoring script. You’ll notice that I use the email function above in my catch blocks; this is because the script is intended to be run as a scheduled task so email makes the most sense to notify of exceptions.

最后,这是实际的监视脚本。 您会注意到,我在catch块中使用了上面的email功能; 这是因为该脚本旨在作为计划任务运行,因此电子邮件最有可能通知异常。

<#
.SYNOPSIS
This script will alert by email, on any datasets that have failed a refresh & a subsequent manual refresh attempt.
 
.DESCRIPTION
This script will iterate through all datasets in all Workspaces within Power BI that the chosen user has access to.
It will then attempt to force a refresh of any datasets with a failed status. The script should be scheduled to run at a regular interval. Upon the next run, it will send a notification email on any failed refreshes made by the API 
(on the last run). There is a time limiter parameter that will stop the repetitive alerting of a failed dataset.
 
.PARAMETER userName
This is the Power BI user that the API will use to query workspaces and datasets. The datasets & groups that are returned
are restricted by the user's permissions
 
.PARAMETER tenantID
# To find your Office 365 tenant ID in the Azure AD portal
# - Login to Microsoft Azure as an administrator.
# - In the Microsoft Azure portal, click Azure Active Directory.
# - Under Manage, click Properties. The tenant ID is shown in the Directory ID box.
 
.PARAMETER clientId
This is the ID generated by the Power BI App created above. It can also be found from
within Azure
 
.PARAMETER client_secret
This is also generated when the Power BI App is created & must be noted as it is
irretrievable once you leave the page
 
.PARAMETER maxTime
The time window of how long you want to alert on failed refreshes via the API. Eg. 30 = If Last refresh end time is beyond 30 mins, do not alert.
This will reduce spam of alert emails when issues may take time to resolve. 
 
.PARAMETER mailServer
Your mail server
 
.PARAMETER mailFrom
Your selected FROM address to send error or notification emails
 
.PARAMETER mailTo
The recipient email address or addresses (separated by semicolons) that will receive
error and notification emails
 
.EXAMPLE
.\PowerBI_Dataset_Alerting.ps1 -userName '[email protected]' -tenantID "85b7f285-XXXX-XXXX-XXXX-ec7116aa9ef5" -clientId "f40daa92-XXXX-XXXX-XXXX-7e027fe03e2e" -client_secret "5bM2KeZl2nVXXXXXXXXXXXXi6IYVPOt8lAtPwXXXXXX="
 
.NOTES
#-------------------------------------------------------------------------------
# Client ID & Client Secret can be obtained by creating a PowerBI app:
# https://dev.powerbi.com/apps
# App Type: Server-side Web app
#-------------------------------------------------------------------------------    
#>
 
[CmdletBinding()]
param
(
    [Parameter(Mandatory=$true)]
    [string]
    $userName = "$(Read-Host 'Power BI Account')",
    
    [string]
    $tenantID,
    
    [Parameter(Mandatory=$true)]  
    [string]
    $clientId,
 
    [Parameter(Mandatory=$true)]  
    [string]
    $client_secret,
 
    [int]
    $maxTime = 30
)
 
begin {
    Write-Verbose 'Add Authentication & Notification Functions'
    . ".\Get-PBIAuthTokenUnattended.ps1"
    . ".\Invoke-AlertEmail.ps1"
 
    if($tenantID = $null)
    {
        Write-Verbose 'Split the string on the username to get the Domain'
        $tenantDomain = $userName.Split("@")[1]
        Write-Verbose 'Querying Azure anonymously (this may not work for ALL tenant domains. Eg. Those that use .onmicrosoft.com)'
        $tenantID = (Invoke-WebRequest https://login.windows.net/$($tenantDomain)/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]
    }
 
}
process {
    try {        
        Write-Verbose 'Authenticate to Power BI using Get-PBIAuthTokenUnattended'
        $auth = Get-PBIAuthTokenUnattended -userName $userName -tenantID $tenantID -clientId $clientId -client_secret $client_secret
 
        Write-Verbose 'Building Rest API header with authorization token'
        $authHeader = @{
        'Content-Type'='application/json'
        'Authorization'='Bearer ' + $auth.access_token
        }
    }
    catch {
        Write-Error 'Authentication failure'
        $script = $MyInvocation.MyCommand.Name	
        $Subject = "$script Error: Authentication Failure"
        $htmlContent = $_.Exception.Message
        Invoke-AlertEmail -title $script -htmlContent $htmlContent -subject $subject -alertColour "#FF5733"  
        throw $_
    }
 
    try{
        Write-Verbose 'Retrieve all Power BI Workspaces'
        $uri = "https://api.powerbi.com/v1.0/myorg/groups"
        $allGroups = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET
 
        Write-Verbose 'Storing time interval provided as window to alert on failed datasets (reduces SPAM from datasets failing regularly)'
        $timeWindow = (Get-Date).AddMinutes(-$maxTime)
        Write-Verbose "Monitor will not alert on API based failures older than $($timeWindow)"
 
        Write-Verbose 'Loop through Workspaces to query datasets' 
        foreach($group in $allGroups.value)
        {                
            Write-Verbose 'Build Group path for API call'    
            $groupsPath = "myorg/groups/$($group.id)"
            
            Write-Verbose 'Build Dataset API String'
            $uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets"
            Write-Verbose 'Return all datasets in Workspace'
            $datasets = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET
            
            Write-Verbose 'Loop through datasets to query refresh info'
            foreach($dataset in $datasets.value)
            {
                if($dataset.isRefreshable -eq $true) #We can only return refresh info on datasets that can be refreshed
                {
                    Write-Verbose 'Build Refresh API String'
                    $uri2 = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$($dataset.id)/refreshes"
                    Write-Verbose 'Return refresh info for each dataset'
                    $refreshes = Invoke-RestMethod -Uri $uri2 -Headers $authHeader -Method GET
 
                    
                    if($($refreshes.value[0].status) -eq 'Failed' -And $($refreshes.value[0].refreshType) -eq 'Scheduled' )
                    {
                        Write-Verbose 'Force refresh of failed Scheduled refreshes'
                        $forcerefresh = Invoke-RestMethod -Uri $uri2 -Headers $authHeader -Method POST
                        #$forcerefresh
                    }
                    
                    elseif ($($refreshes.value[0].status) -eq 'Failed' -And $($refreshes.value[0].refreshType) -eq 'ViaApi' -And [DateTime]$($refreshes.value[0].endTime) -gt $timeWindow)
                    {
                        Write-Verbose 'Notifying of refreshes that failed via the API'
                        #Build email HTML and pass to function
                        $title = "Power BI Dataset Alerting"
                        $subject = "$($title): $($dataset.name)"
                        $htmlContent = "
Scheduled & Forced Refreshes have both failed! Please investigate
"
                        $htmlContent += "
Workspace: $($group.name)
"
                        $htmlContent += "
"
                          Invoke-AlertEmail -title $title -htmlContent $htmlContent -subject $subject -alertColour "#F2C811"                                                                                       }                 }               }             $datasets = $null         }     }     catch{         Writ-Error 'Data collection failure'         $script = $MyInvocation.MyCommand.Name         $subject = "$script Error: Data Collection Failure"         $htmlContent = $_.Exception.Message         Invoke-AlertEmail -title $script -htmlContent $htmlContent -subject $subject -alertColour "#FF5733"           throw $_     } }

Here’s an overview of what the script does:

以下是该脚本的概述:

You will want to schedule the monitor script to run at the interval to suit your SLA/OLAs. I set it to run every 15 minutes. This means, at the longest interval, it would take up to 14 minutes to detect a failed dataset, force a manual refresh, then another 15 minutes before it would email out to warn of the failure. This is a good window to accommodate a timeout failure where the manual refresh might run for a while before completing or failing again.

您将希望安排监视脚本以适合您的SLA / OLA的时间间隔运行。 我将其设置为每15分钟运行一次。 这意味着,在最长的时间间隔内,最多需要14分钟才能检测到失败的数据集,强制进行手动刷新,然后再过15分钟,它将通过电子邮件发出警告失败的消息。 这是一个很好的窗口,可以解决超时失败的问题,在这种情况下,手动刷新可能会运行一段时间,然后再完成或再次失败。

糟糕,这是哪里出了问题… (Oops, this is what went wrong…)

So, my dataset has failed and then failed again when we tried to force a refresh which means it’s likely not a short-term issue that will resolve itself. The refresh failure email will then be sent to your chosen recipient(s).

因此,我的数据集失败了,然后在我们尝试强制刷新时又失败了,这意味着它可能不会解决自己的短期问题。 然后,刷新失败电子邮件将发送给您选择的收件人。

It’s going to contain:

它将包含:

  • A relevant title, (in this case, the name/purpose of the script)

    相关标题(在这种情况下,为脚本的名称/用途)
  • The name of the parent workspace & a hyperlink to that workspace

    父工作空间的名称以及该工作空间的超链接
  • The name & a link to the failing dataset’s settings page so you can diagnose the failure easily

    名称和指向失败数据集的设置页面的链接,以便您可以轻松诊断失败
  • A courteous Thank you from the script owner ? (which can be set in the parameters)

    礼貌的谢谢脚本所有者? (可以在参数中设置)

Some things to consider with this script:

此脚本要考虑的一些事项:

  • The user account you use to connect to Power BI with is very important, it doesn’t have to own any of the datasets but it cannot monitor datasets if it doesn’t have the permission to the workspace the dataset is contained in. Bear this in mind. In my case, I have implemented an admin account that gets added to all workspaces as a matter of process but even this can miss user created workspaces. You may have better luck with an Azure admin. Please let me know if you do.

    用于连接到Power BI的用户帐户非常重要,它不需要拥有任何数据集,但是如果没有对包含该数据集的工作区的许可,它就无法监视数据集。心里。 就我而言,我已经实现了一个管理员帐户,该帐户作为过程已添加到所有工作空间中,但是即使这样也会丢失用户创建的工作空间。 使用Azure管理员可能会更好。 请让我知道。

使用PowerShell进行进一步分析 (Further analysis with PowerShell)

You can use an extension of this script to query all dataset refresh history & store it in a local database. This could be used to pick up more nuanced issues

您可以使用此脚本的扩展名来查询所有数据集刷新历史记录并将其存储在本地数据库中。 这可以用来解决更多细微的问题

  • Repeated failure trends

    反复失败的趋势
  • Refresh durations over time

    随时间刷新持续时间
  • Datasets being refreshed too often, or not often enough

    数据集刷新太频繁或不够频繁

参考资料 (References)

  • Connect & Query Power BI with PowerShell使用PowerShell连接和查询Power BI
  • My GitHub Profile我的GitHub个人资料
  • Dead ‘Learn More’ Link无效的“了解详情”链接
  • Troubleshooting Refresh Scenarios刷新方案故障排除
  • Power BI App RegistrationPower BI App注册
  • StackOverflow TenantID commandStackOverflow TenantID命令

翻译自: https://www.sqlshack.com/manage-power-bi-dataset-refresh-failures/

power bi 数据刷新

你可能感兴趣的:(power bi 数据刷新_如何管理Power BI数据集刷新失败)