0

i'm simply trying to concatenate a value that I output in a .csv file with % with this syntax

$item | Add-Member -type NoteProperty -Name '% Left Completed' -Value $LeftCompleted.ToString("#.##") + '%'

but im getting A positional parameter cannot be found that accepts argument '%' error, how do i concatenate them? for example right now its just 12, whereas i want to see 12%

Jack Rogers
  • 458
  • 5
  • 18
  • 1
    Enclose the concatenation in $(): `-Value $($LeftCompleted.ToString("#.##") + '%')`. This will make powershell evaluate the expression _before_ passing the resulting value to the Value parameter – Mathias R. Jessen Oct 22 '21 at 17:40
  • @MathiasR.Jessen sir thank u for helping my career, kind regards - bob – Jack Rogers Oct 22 '21 at 17:50
  • In short: In order to pass the result of an _expression_ or output from another _command_ as an argument to a command, you need to enclose the expression / nested command in `(...)` - while `$(...)` typically works too, it is unnecessary and can have side effects - see [this answer](https://stackoverflow.com/a/58248195/45375). – mklement0 Oct 22 '21 at 18:16

0 Answers0