There are a "few" PowerShell scripts around to get this done:
https://gallery.technet.microsoft.com/scriptcenter/Azure-ARM-VM-Inventory-57ba01b7
https://christoph.vollmann.co/2020/02/export-your-azure-inventory-as-csv-files/
https://gist.github.com/marckean/0d35d11b112f44313a440df10d1ff152
https://github.com/manjunathrao/manjunathrao-blog/blob/main/PowerShell/Get-AzInventory.ps1
Maybe one of these fits your requirement or is a good start to customise to your needs.
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten