Retrieve the AWS Marketplace product code from your instance
You can retrieve the AWS Marketplace product code for your instance using its instance metadata. If the instance has a product code, Amazon EC2 returns it. For more information about retrieving metadata, see Access instance metadata for an EC2 instance.
To retrieve a product code, use the command for your instance's operating system.
PS C:\>
Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/product-codes