Как получить ID установщика Powershell Azure

Я нашел код, который загружает и устанавливает какую-то программу из установщика веб-платформы. Он успешно работает, но мне нужно вместо этого программного обеспечения скачать и установить Azure PowerShell. Итак, как изменить код (или как получить id powershell azure)?

    using System;
    using System.Collections.Generic;
    using Microsoft.Web.PlatformInstaller;

    namespace CustomProductInstaller
    {
        class Program
        {
            protected readonly static string MainXml = "https://go.microsoft.com/fwlink/?LinkId=158722";
            protected readonly static string CustomXml = "http://blogs.iis.net/blogs/kateroh/SIR/SIRWebPIFeed.xml";

            protected readonly static string CustomProductId = "AppGallerySIRBinaries";//Need change here to ID Azure PowerShell
            protected readonly static string CustomAppId = "AppGallerySIRApp";//Need change here to ID Azure PowerShell

            private static bool _installCompleted = false;

            static void Main(string[] args)
            {
                ProductManager productManager = new ProductManager();

                // 1. Load main product feeds
                productManager.Load
                    (
                        new Uri(MainXml), // location of the main feed 
                        false,            // load products for all architectures and platforms
                        true              // load enclosures (eg WebApplicationList.xml)
                    );

                // 2. Load custom feed
                productManager.LoadExternalFile(new Uri(CustomXml));

                // 3. Find the custom product by product Id
                Product customProduct = productManager.GetProduct(CustomProductId);
                Product customApp = productManager.GetProduct(CustomAppId);

                // 4. Find all products to install (custom product + its dependencies)
                List<Product> productsToInstall = new List<Product>();
                AddProductWithDependencies(customProduct, productsToInstall);
                AddProductWithDependencies(customApp, productsToInstall);

                // 5. Pick the right installers - for the chosen language, if such is not available, fall back to English
                List<Installer> installersToUse = new List<Installer>();
                Language languageOfInstallers = productManager.GetLanguage("fr");
                Language english = productManager.GetLanguage("en");

                foreach (Product productToInstall in productsToInstall)
                {
                    Installer currentInstaller = productToInstall.GetInstaller(languageOfInstallers);
                    if (currentInstaller == null)
                    {
                        currentInstaller = productToInstall.GetInstaller(english); ;
                    }
                    installersToUse.Add(currentInstaller);
                }

                // 6. Prepare installers
                InstallManager installManager = new InstallManager();
                installManager.Load(installersToUse);

                // 7. Sign up for installation events
                installManager.InstallerStatusUpdated += new EventHandler<InstallStatusEventArgs>(InstallManager_InstallerStatusUpdated);
                installManager.InstallCompleted += new EventHandler<EventArgs>(InstallManager_InstallCompleted);

                foreach (InstallerContext installerContext in installManager.InstallerContexts)
                {
                    string failureReason;
                    installManager.DownloadInstallerFile(installerContext, out failureReason);
                }

                // 8. Install products first
                installManager.StartInstallation();
                while (!_installCompleted) ;
                _installCompleted = false;

                // 9. At this point all products in ProductManager are downloaded, so we can set parameters on the application
                // NOTE: you cannot set application parameters, before it is downloaded
                // in this case, the language of the Web Deploy package does not matter, since it is not displayed in the UI
                Installer appInstaller = customApp.GetInstaller(english);
                foreach (DeclaredParameter declaredParameter in appInstaller.MSDeployPackage.DeclaredParameters)
                {
                    // set values of parameters that do not have default values
                    if (string.IsNullOrEmpty(declaredParameter.DefaultValue))
                    {
                        appInstaller.MSDeployPackage.SetParameters[declaredParameter.Name] = "New Value";
                    }
                }

                // 10. Then install applications (because application might have product dependencies, but not vice versa)
                installManager.StartApplicationInstallation();
                while (!_installCompleted) ;

                Console.ReadKey();
            }

            private static void AddProductWithDependencies(Product product, List<Product> productsToInstall)
            {
                // avoid duplicates 
                if (!productsToInstall.Contains(product))
                {
                    productsToInstall.Add(product);
                }

                // GetMissingDependencies will check whether any dependencies are not installed for the product
                // AND are not already added to the install list (productsToInstall)
                ICollection<Product> missingDependencies = product.GetMissingDependencies(productsToInstall);
                if (missingDependencies != null)
                {
                    foreach (Product dependency in missingDependencies)
                    {
                        AddProductWithDependencies(dependency, productsToInstall);
                    }
                }
            }

            private static void InstallManager_InstallerStatusUpdated(object sender, InstallStatusEventArgs e)
            {
                Console.WriteLine(e.InstallerContext.ProductName + ": " +
                                  e.InstallerContext.InstallationState + ". " +
                                  e.InstallerContext.ReturnCode.DetailedInformation +
                                  "Progress: " + e.ProgressValue.ToString());
            }

            private static void InstallManager_InstallCompleted(object sender, EventArgs e)
            {
                Console.WriteLine("Installation completed");
                _installCompleted = true;
            }
        }
    }

0 ответов

Другие вопросы по тегам