Passing Azure DevOps WI field names in PowerShell to Az DevOps CLI as variables
The Issue
The Azure DevOps CLI command az boards work-item update can take a list of fields as a set if value pairs e.g.
az boards work-item update --id 123 --fields Microsoft.VSTS.Scheduling.Effort=10
However, if you try to replace the field name with a variable in PowerShell like this
$fieldname = "Microsoft.VSTS.Scheduling.Effort"
az boards work-item update --id 123 --fields $fieldname=10
you will get an error like this
The –fields argument should consist of space separated “field=value” pairs.
The Solution
The solution is simple, and the same one required if you wish to pass multiple fields into the command, you need to wrapper the set of key value pairs for the fields in quotes e.g.
$fieldname = "Microsoft.VSTS.Scheduling.Effort"
az boards work-item update --id 123 --fields "$fieldname=10"
Once this is done the command will work as expected.
For the original version of this post see Richard Fennell's personal blog at Passing Azure DevOps WI field names in PowerShell to Az DevOps CLI as variables