Wait for an AlwaysOn replica to be synchronized in Powershell
I found my problem.

I was working under the wrong assumption that the objects were automatically refreshed in Powershell. I added a "$NewPrimary.Refresh()" insinde of the while loop and that did the trick.

I hope this helps someone with the same wrong assumption in the future.