There are plenty of scripts already written that produce reports with varying levels of detail. One of them should provide you with at least a starting point to write your own script, or to add to one that provides almost all of what you want.
A quick search of the web using "powershell get o365 license" is a place to begin.