DisplayName pulled from Registry breaks logging

I’m working on an uninstall for Alteryx Designer. The script works, but logging stops in the middle of the process. I’ve determined that the problem is the DisplayName value I’m pulling from the applications Uninstall key.

In Regedit, DisplayName appears to be ‘Alteryx 2021.2 x64 (Remove only)’
PowerShell retrieves 'Alteryx 2021.2 x64 (Remove only) a ’

If I add a breakpoint and change the value Powershell retrieved from the registry so it doesn’t include the bogus character(s), the script keeps logging.

If I remove the ) at the end of DisplayName in RegEdit and replace it with ), the scripts logs correct.

We checked the string length. Unmodified the string is 45 characters long. After replacing the ) with ) its 32 characters. Whatever these weird characters are, they break the log file. NO more logging takes place, even if I rerun the script, until I delete the file.

I don’t think this is a PSADT problem. I’m thinking that the application installation is writing something bogus to the registry. What I’m wondering if how can I identify when this happens, and what can I do about it. For this uninstall, I’m going to write something that will re-write the DisplayName for this application, but I’m looking for something more universal.

Try this:

$DisplayName = $DisplayNameFromReg | Out-String
#Out-String cleans up stuff so that strings don't contain garbage.

.
Also, Write-Log cannot handle empty string so give it something to chew on:

Write-Log "[$DisplayName ]"
#This way, Write-Log will log [ ] if $DisplayName  is empty or $null

I will keep this in mind for next time. That sounds easier than the machinations I went through to fix the value data in the registry.