microsoft / Partner-Center-PowerShell

PowerShell module for managing Partner Center resources.
https://docs.microsoft.com/powershell/partnercenter/
MIT License
130 stars 59 forks source link

Get all products with all target view and segments #393

Closed n9839950 closed 1 year ago

n9839950 commented 2 years ago

Is there an api endpoint to get all the products? below code raises an exception when i get all possible products.

` var targetView = new List { "Azure", "AzureReservations", "AzureReservationsVM", "AzureReservationsSQL", "AzureReservationsCosmosDb", "OnlineServices", "Software", "SoftwareSUSELinux", "SoftwarePerpetual", "SoftwareSubscriptions" };

        var segmentList = new List<string> { "government", "education", "commercial", "nonprofit" };
        var productList = new List<Product>();

        foreach (var target in targetView)
        {
            foreach (var segment in segmentList)
            {

                try
                {
                    var products = appPartnerOperations.Products.ByCountry(countryCode).
                        ByTargetView(target).ByTargetSegment(segment).Get().Items;
                    foreach (var product in products)
                    {
                        productList.Add(product);
                    }

                }
                    catch (PartnerException ex)
                {
                    var messsage = ex.Message;
                    throw;
                }

            }
        }

`