In the PowerShell Slack, I recently answered a question along these lines. Say you have a string that reads “first thing {} second thing {}” and you want to get to “first thing {0} second thing {1}” so that you can use the -f operator to insert values into those spots. For instance…
"first thing {0} second thing {1}" -f $(get-date -format yyyy-MM-dd), $(get-random)
# Will return "first thing 2018-01-10 second thing <a random number>"
The question is: how can you replace the {}’s in the string to {<current number>}?
[regex]::replace($string, “{}”, {“{$($i)}”; $i++})
[regex]::replace($string, “{}”, {“{$($global:i)}”; $global:i++})