Try this -
$Key = "<add key=`"uniqueID`" value=`"$($uniqueID)`" />"
OR
$Key = "<add key=`"uniqueID`" value=`"$uniqueID`" />"
To force Windows PowerShell to interpret a double quotation mark
literally, use a backtick character. This prevents Windows PowerShell
from interpreting the quotation mark as a string delimiter.
INFO -
If you look at Get-Help about_Quoting_Rules, it says,
SINGLE AND DOUBLE-QUOTED STRINGS
When you enclose a string in double quotation marks (a double-quoted
string), variable names that are preceded by a dollar sign ($) are
replaced with the variable's value before the string is passed to the
command for processing.
For example:
$i = 5
"The value of $i is $i."
The output of this command is:
The value of 5 is 5.
Also, in a double-quoted string, expressions are evaluated, and the
result is inserted in the string. For example:
"The value of $(2+3) is 5."
The output of this command is:
The value of 5 is 5.
When you enclose a string in single-quotation marks (a single-quoted
string), the string is passed to the command exactly as you type it.
No substitution is performed. For example:
$i = 5
'The value of $i is $i.'
The output of this command is:
The value $i is $i.
Similarly, expressions in single-quoted strings are not evaluated. They
are interpreted as literals. For example:
'The value of $(2+3) is 5.'
The output of this command is:
The value of $(2+3) is 5.
The reason your code wasn't evaluating the value was because you were using a single quote to wrap the variable $key. Wrapping it with double quote and using a sub-expression operator ($($UniqueID) along with backtick does the trick, or simply using the $UniqueID will also suffice.
$Key = "<add key='uniqueID' value='$uniqueID' />". Better yet, don't build your XML by string concatenation. PowerShell comes with an XML parser. Use it.