The Regex -Replace
operator can be used to achieve the results. This replaces everything up until the first =
character with id
.
$Copyboard = $Copyboard -Replace "^[^=]+","id"
Using the -Split
operator, you can prepend id=
to the query value. I am splitting with the =
character as the delimiter and returning all data after the =
with the [1]
index. Here I used the format operator (-f
), but you can use any concatenation technique you choose.
$Copyboard = "{0}{1}" -f 'id=',($Copyboard -Split "=")[1]
An alternative approach is to first cast $Copyboard
as a [uri]
, which opens up other options for your code later only if you don't reassign $Copyboard
with the new value. Then access the property (query
in this case) you want to change and only output that changed property. With the uri object, the different parts of the copied uri are broken down into subparts and the resulting subparts are stored as properties of the object.
Using the regex -Replace
operator with the uri object:
([uri]$copyboard).Query -Replace "^[^=]+","id"