コード例 #1
0
        /// <summary>
        /// Gets the user account id if the user logs in, otherwise empty string.
        /// </summary>
        private string GetUserAccountId()
        {
            try
            {
                var output = AzContext.ExecuteScript <string>("(Get-AzContext).Account.Id");
                return(output.FirstOrDefault() ?? string.Empty);
            }
            catch (Exception)
            {
            }

            return(string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// Gets the latest version from the loaded Az modules.
        /// </summary>
        private Version GetAzVersion()
        {
            Version latestAz = DefaultVersion;

            try
            {
                var outputs = AzContext.ExecuteScript <PSObject>("Get-Module -Name Az -ListAvailable");
                foreach (PSObject obj in outputs)
                {
                    string  psVersion = obj.Properties["Version"].Value.ToString();
                    int     pos       = psVersion.IndexOf('-');
                    Version currentAz = (pos == -1) ? new Version(psVersion) : new Version(psVersion.Substring(0, pos));
                    if (currentAz > latestAz)
                    {
                        latestAz = currentAz;
                    }
                }
            }
            catch (Exception)
            {
            }

            return(latestAz);
        }