Hi Andrea,
To get the password back normally it's enough to have isAdminPasswordEnabled == true and see it in the UI (because auto-generated password is only set during first power-on when customization trigger, not when you simply set the flag in VM properties). Does it return manual password for you? If not you might be hitting a regression which was in one of 5.1.x releases. There is a hot patch available for 5.1.2.
/Andrii