Letter of recommendation from a professor with whom I took a class I understand that there are many posts similar to this, however I believe (upon reading other posts), that this thread would not be redundant.  I am an undergrad currently applying to grad schools and am in the process of asking for recommendation letters from professors.  Prior to my current university, I was at a different institution where I took courses.  There is a particular professor I am interested in asking for a letter from, however it has been two years and since then he has moved to a different university.  My reasoning for asking him for a letter is that I took his PhD course as an undergrad and received a better grade than over half the PhD students (not trying to brag but trying to emphasize there are some non-generic characteristics about me).  In addition, he is a well-known individual in my area of studies.  Given that I took his course two years ago is it still appropriate to ask?  A concern of mine is that it will be a generic letter of rec which I have read admissions committees don't like.
Yes, it is appropriate to ask. There is never any issue about that. He may automatically remember you if you stood out as two years isn't that long. But you may need to remind him of the course and say some things about what you've been doing since. 

The best way to manage this is face to face. I mention this even though it may now be impossible with the pandemic, and may be hard in any case due to distance. But actually seeing you would help jog his memory. But perhaps you have photos online somewhere to help refresh his memory. 

You can also ask him whether he thinks a letter from him would be helpful or not. He might be able to say more than you think. The main reason for a letter is so that an independent person makes a prediction about your suitability for a program and your likelihood of success. Perhaps he can do that easily. If he has any hesitation, then you'd be better off asking someone else. 

I had a few standout students in my teaching career. It would be easy to write recommendations for them even though our interactions were brief. If you made an impact it can work out.