In ADB shell issue the following command:
dumpsys package packages
This gives you all the information about installed packages, including the version number. You can then play around with grep
utility to narrow down the results to only the lines you need:
dumpsys package packages | grep -E 'Package \[|versionName'
The above returns something similar to this:
Package [com.android.voicedialer] (41cb1a08):
versionName=4.4.2-323cb6b305
Package [com.android.defcontainer] (41cb4750):
versionName=4.4.2-323cb6b305
Package [ru.ok.android] (41cb7200):
versionName=3.7.5
Package [org.koxx.pure_calendar] (41cb9818):
versionName=3.3.3
Package [com.android.phone] (41df4fe8):
versionName=4.4.2-323cb6b305
Package [com.gsamlabs.xposed.mods.enablebatterystatspermission] (41cbc008):
versionName=1.2
...