Jeff Iannucci has a script which removes ad hoc plans from the Query Store:
Now, rather than being my usual rambling self I want to be very direct here: this solution will NOT give you the same behavior as “optimize for ad hoc workloads.” That setting keeps query info without the plan during the first execution, but then keeps the plan after the second execution.
That’s kinda like a surgeon with a scalpel. What is below is much more drastic. We’re going to break out a chainsaw for Query Store.
Chainsaw solutions to scalpel problems? Now you have my interest.