I am running
$nameLine= az boards iteration team list --team "DevOpsTesting Team" --timeframe current --project DevOpsTesting | findstr "name"
$nameOnly = (select-string ":(.*)" -inputobject $name).Matches.Groups[1].Value.Replace(",","")
az boards work-item create --title Test --type Task --project DevOpsTesting --iteration DevOpsTesting\\$nameOnly --assigned-to A.B@gmail.com --fields "Description=PR is open, please test the new exe version and approve Priority=2"
But because the value of nameOnly is "Sprint 7" I am getting an error
az : ERROR: unrecognized arguments: 7
At line:4 char:1
..? thx.
If spaces are used within a iteration, then enclose in double-quotes, in your case you could add the doule-quotes like:
--iteration "DevOpsTesting\\$nameOnly"