Set-regkey only when Installation is succesfull


We want to have a registry key populated with the names of all installations coming from packages.
Is there not an easy way to check if an installation succeeds and then use SET-REGKEY to add a package specific reg-key?
As we use the toolkit the name of the .msi is adapted to have the full package name in the logfile so it even should be possible to have all this added to the ZERO CONFIG MSI installations

If I use the SET-Regkey under Post installation it always executes even if the .msi is not installed.

Kind Regards

If (Get-InstalledApplication -Name NewApplication) {
Set-RegistryKey -Key RegPathHere -Name ‘RegNameHere’ -Value RegValueHere