Error popup with PSADT running in silent mode

Maybe but it seems like your line 161 is the issue.
If the following is your line 161:

$InstalledUserApp | Remove-AppxPackage -AllUsers

I suspect the problem is what’s in $InstalledUserApp .
Is it empty? Is it good?
We can’t tell because you skimped on the logging.

See below on how to add it to the Remove-AppxPackage command:

As for determining what’s in $InstalledUserApp , you might be able to add an additional line before line 161 to log its contents. I’m assuming it’s an array so this should work:

Write-log "Contents of InstalledUserApp [$($InstalledUserApp | Out-string)]"