How about building a .ps1 script and executing it? That way you can easily see what code is being generated.
# Here is data that comes from somewhere else.
$Title = "Hello There"
$WhoamiSwitch = "/user"
# Now build our script
$Myps1 = "$env:TEMP\myscript.ps1" # a temporary file
'write-host "This is my script test"' | out-file $Myps1 # use single quote so that $ variables do not get expanded
'cd \' | out-file $Myps1 -Append # note that this is the second out-file and the first with -append
'$host.ui.RawUI.WindowTitle = "{0}"' -f $Title | out-file $Myps1 -Append # put the contents of the $title variable into the command to be executed
'whoami.exe {0}' -f $WhoamiSwitch | out-file $Myps1 -Append # same with the whoami switch
'"`n----------------------------------------"' | out-file $Myps1 -Append
'"Here is what my script contains:`n"' | out-file $Myps1 -Append
'start-process notepad.exe "{0}"' -f $Myps1 | out-file $Myps1 -Append
Start-Process powershell.exe -ArgumentList '-noexit', $myps1