pwsh/Clear-AppCompatCache.ps1

using namespace System.Security.Principal

function Clear-AppCompatCache {
  <#
    .SYNOPSIS
        Flushes the application compatibility cache.
    .DESCRIPTION
        The data of cache is stored in the registry by path
        HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache
    .INPUTS
        None
    .OUTPUTS
        System.Boolean
    .NOTES
        MIT
    .LINK
        None
  #>

  [CmdletBinding()]param()

  process {
    .({
      Write-Warning 'administrator rights (elevated shell) is required.'
    },{
      New-Delegate kernel32 {
        bool BaseFlushAppcompatCache
      }

      $kernel32.BaseFlushAppcompatCache.Invoke()
    })[[Int32][WindowsPrincipal]::new(
      [WindowsIdentity]::GetCurrent()
    ).IsInRole([WindowsBuiltInRole]::Administrator)]
  }
}

Export-ModuleMember -Function Clear-AppCompatCache