When you create a new Microsoft 365 group in the Microsoft 365 portal, you cannot work with group licensing in Azure Active Directory because the group's SecurityEnabled property has the value "false".
If you create a new Microsoft 365 group in Azure Active Directory, you can work with group licensing in Azure AD because the SecurityEnabled property has a value of "true".
Let's explore this together.
I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):
#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE