Insert variables or API output into table

178 views Asked by At

Below is a PowerShell script that will give me all the below fields of a particular work item in Visual Studio Online. My goal is to put all the fields into a table. If I could write those variables into a row, that would be fantastic, or if there is a simple way of doing this, please share :)

I would like the out put to be similar to:

Col1     Col2     Col3    Col4
  ID     Desc     Name    Date

This is my script:

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
0

There are 0 answers