Forum Discussion
RaviKiranS
May 04, 2023Copper Contributor
How to add a comment with rich text (text+images) to the work item (task) with Powershell
Hi All,
I am trying to add a comment into discussion and other custom fields based of rich text programmatically (using PowerShell). Can you please guide me how to upload the image. I browsed onlin...
Kidd_Ip
Sep 12, 2025MVP
Take this:
$org = "https://dev.azure.com/yourOrg"
$project = "yourProject"
$workItemId = 1234
$pat = "yourPersonalAccessToken"
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
"Content-Type" = "application/json"
}
$imageUrl = "https://yourdomain.com/path-to-image.jpg"
$commentText = "<p>This is a rich text comment with an image:</p><img src='$imageUrl' alt='Image' width='300' />"
$body = @{
text = $commentText
} | ConvertTo-Json -Depth 3
Invoke-RestMethod -Uri "$org/$project/_apis/wit/workItems/$workItemId/comments?api-version=7.0" `
-Method Post -Headers $headers -Body $body