用于导出sprint PBI的Powershell函数/脚本[关闭]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于导出sprint PBI的Powershell函数/脚本[关闭]相关的知识,希望对你有一定的参考价值。

我想使用powershell脚本导出VSTS中的所有PBI。我们正在使用Azure Devops进行Sprint管理。以下是我要执行的任务。

对VSTS进行身份验证在VSTS中查询特定队列下的PBI列表-检索有用的字段-标题,分配给,州,地区,迭代,优先级,工作量-检索链接的工作(向上或向下)可根据分配给可按州过滤

有人可以帮我使用Powershell脚本吗?

答案

[有时,某人可能只是为您准备了一些东西,但并非正常情况。有点像我要在这里开始的工作。

示例:

使用此的简单快速搜索:

PowerShell 'export vsts PBI'

当然,您会获得很多列表,如下所示,您可以根据需要进行调整:

[Export Visual Studio Team Services Work Items Using PowerShell加上作者的示例代码。

function Export-VSTSWorkItem  
{  
<#  
.SYNOPSIS  
    A PowerShell function to export Visual Studio Team Servies work items.   
.DESCRIPTION  
    A PowerShell function to export Visual Studio Team Servies work items.   
.EXAMPLE  
    PS C:> Export-VSTSWorkItem -Instance 'Fabrikam' -Token "PAT" -WorkItemType Bug  
    Yields all the bugs in from the work items table.  
.EXAMPLE  
    PS C:> Export-VSTSWorkItem -Instance 'Fabrikam' -Token "PAT" -WorkItemType Task  
    Yields all the task in from the work items table.  
.EXAMPLE  
    PS C:> Export-VSTSWorkItem -Instance 'Fabrikam' -Token "PAT" -WorkItemType Epic  
    Yields all the epic in from the work items table.  
.EXAMPLE  
    PS C:> Export-VSTSWorkItem -Instance 'Fabrikam' -Token "PAT" -WorkItemType Epic -ExportAs Csv  
    Exports information as csv  
.EXAMPLE  
    PS C:> Export-VSTSWorkItem -Instance 'Fabrikam' -Token "PAT" -WorkItemType Epic -ExportAs Fancyhtml  
    Exports information as a fancy html  
.NOTES  
    @ChendrayanV  
#>  
    [CmdletBinding()]  
    param (  
        # Visual Studio Team Services Account Name  
        [Parameter(Mandatory)]  
        $Instance,  

        # Create a Personal Access Token  
        [Parameter(Mandatory)]  
        $Token,  

        # Opt the Work Items Type. (Modify as required)  
        [Parameter(Mandatory)]  
        [ValidateSet('Bug', 'Task', 'Epic', 'Feature')]  
        $WorkItemType,  

        # Export in your favorite format.  
        [Parameter()]  
        [ValidateSet('Csv', 'HTML', 'FancyHTML')]  
        $ExportAs  
    )  

    begin  
    {  
    }  

    process  
    {  
        $Authentication = (":$Token")  
        $Authentication = [System.Text.Encoding]::ASCII.GetBytes($Authentication)  
        $Authentication = [System.Convert]::ToBase64String($Authentication)  
        switch ($WorkItemType)  
        {  
            "Bug"  
            {  
                $Body = @{  
                    Query = "Select * from WorkItems WHERE [System.WorkItemType] = '$WorkItemType'"  
                } | ConvertTo-Json  
            }  
            "Task"  
            {  
                $Body = @{  
                    Query = "Select * from WorkItems WHERE [System.WorkItemType] = '$WorkItemType'"  
                } | ConvertTo-Json  
            }  
            "Epic"  
            {  
                $Body = @{  
                    Query = "Select * from WorkItems WHERE [System.WorkItemType] = '$WorkItemType'"  
                } | ConvertTo-Json  
            }  
            "Feature"  
            {  
                $Body = @{  
                    Query = "Select * from WorkItems WHERE [System.WorkItemType] = '$WorkItemType'"  
                } | ConvertTo-Json  
            }  
        }  
        $RestParams = @{  
            Uri         = "https://$Instance.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.0"  
            Method      = "Post"  
            ContentType = "application/json"  
            Headers     = @{  
                Authorization = ("Basic {0}" -f $Authentication)  
            }  
            Body        = $Body  
        }  
        try  
        {  
            $Id = (Invoke-RestMethod @RestParams).workitems.id -join ","  
            if ($Id -ne $null)  
            {  
                $Fields = @('System.Id', 'System.Title', 'System.AssignedTo',   
                    'System.State', 'System.CreatedBy', 'System.WorkItemType') -join ","  
                $RestParams["Uri"] = "https://$Instance.visualstudio.com/DefaultCollection/_apis/wit/WorkItems?ids=$Id&fields=$Fields&api-version=1"  
                $RestParams["Method"] = "Get"  
                $RestParams.Remove("Body")  
                $Result = Invoke-RestMethod @RestParams  
                if (! $PSBoundParameters['ExportAs'])  
                {  
                    ($Result.value.fields)  
                }  
            }  
            else  
            {  
                Write-Warning "No Items are available in $WorkItemType"  
            }  

            switch ($ExportAs)  
            {  
                'csv'  
                {  
                    $Result.value.fields | Export-Csv .WITReport.csv -NoTypeInformation   
                }  
                'HTML'  
                {  
                    $Result.value.fields | Export-Csv .WITReport.html -NoTypeInformation   
                }  
                'FancyHTML'  
                {  
                    Add-Content  ".style.CSS"  -Value " body {   
                    font-family:Calibri;   
                    font-size:10pt;   
                    }   
                    th {    
                    background-color:black;   
                    color:white;   
                    }   
                    td {   
                    background-color:#19fff0;   
                    color:black;}"  
                    $Result.value.fields | ConvertTo-Html -CssUri .Style.css | Out-File .Report.html  
                }  
            }  
        }  
        catch  
        {  
            $_.Exception.Message   
        }  
    }  

    end  
    {  
    }  
} 

此外,请务必检查MSDN上的DevOps API documentation以及类似...的项目

'There is no option available to export the backlog items and bugs to excel'

您需要在VSTS帐户中安装Open in Excel扩展名(https://marketplace.visualstudio.com/items?itemName=blueprint.vsts-open-work-items-in-excel),然后创建一个查询,该查询可以搜索您的积压项目和所需的错误。

以上是关于用于导出sprint PBI的Powershell函数/脚本[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

修改团队基础服务器中 Sprint Board 的列

powershell Powershell命令用于导出Azure AD并导入到本地AD

端午献好文Scrum框架下如何管理未完成或部分完成的工作

Scrum框架下如何管理未完成或部分完成的工作

Scrum协作稳定性保障——DoR和DoD

PBI之模拟ABC 分析矩阵的建模(一)