0

下面是一个 PowerShell 脚本,它将为我提供 Visual Studio Online 中特定工作项的所有以下字段。我的目标是将所有字段放入一个表中。如果我可以将这些变量写成一行,那就太好了,或者如果有一种简单的方法可以做到这一点,请分享:)

我希望输出类似于:

Col1 Col2 Col3 Col4
  ID 描述 名称 日期

这是我的脚本:

param(
  $vstsAccount,
  $projectName,
  $user,
  $token,
  $workitemid
)

Function QueryWorkItem{
  # Base64-encodes the Personal Access Token (PAT) appropriately
  $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

  # Construct the REST URL to obtain Build ID
  $uri = "https://$($vstsAccount).visualstudio.com/defaultcollection/_apis/wit/workitems/$($workitemid)?api-version=1.0"

  # Invoke the REST call and capture the results (notice this uses the PATCH method)
  $result = Invoke-RestMethod -Uri $uri -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Get 

  $areapath = $result.fields.'system.areapath'
  $TeamProject = $result.fields.'System.TeamProject'
  $IterationPath = $result.fields.'System.IterationPath'
  $workitemtype = $result.fields.'system.workitemtype'
  $state = $result.fields.'System.State'
  $Reason = $result.fields.'System.Reason'
  $AssignedTo = $result.fields.'System.AssignedTo'
  $CreatedDate = $result.fields.'System.CreatedDate'
  $CreatedBy = $result.fields.'System.CreatedBy'
  $Title = $result.fields.'System.Title'
  $ClosedDate = $result.fields.'Microsoft.VSTS.Common.ClosedDate'
  $ClosedBy = $result.fields.'Microsoft.VSTS.Common.ClosedBy'
  $StateChangedDate = $result.fields.'Microsoft.VSTS.Common.StateChangeDate'
  $ActivatedDate = $result.fields.'Microsoft.VSTS.Common.ActivatedDate'
  $ActivatedBy = $result.fields.'Microsoft.VSTS.Common.ActivatedBy'
  $Priority = $result.fields.'Microsoft.VSTS.Common.Priority'
  $StoryPoints = $result.fields.'Microsoft.VSTS.Scheduling.StoryPoints'
  $Risk = $result.fields.'Microsoft.VSTS.Common.Risk'
  $ValueArea = $result.fields.'Microsoft.VSTS.Common.ValueArea'
  $Tags = $result.fields.'System.Tags'

  #not proper syntax
  insert into table (all values)
}

QueryWorkItem
4

0 回答 0