/// <summary> /// Performs execution of the command /// </summary> protected override void DoProcessRecord() { const string cmd = "_GetConnectionString -Version $args[0]"; const string localTemplate = "{0}"; // const string remoteTemplate = "Invoke-Command -ScriptBlock {{ {0} }} -ArgumentList $args[0] "; // const string remoteComputerTemplate = remoteTemplate + " -Computer $args[1] -Credential $args[2]"; // const string remoteSessionTemplate = remoteTemplate + " -Session $args[1]"; var funcCode = File.ReadAllText(Path.Combine( MyInvocation.MyCommand.Module.ModuleBase, "Private/Admin.ps1" )); object session = null; object credential = null; string invokeCmd; if (Session != null) { throw new NotImplementedException("Remote sessions are currently not supported"); // invokeCmd = string.Format(remoteSessionTemplate, cmd); // session = Session; } else if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException("Remote computers are currently not supported"); // invokeCmd = string.Format(remoteComputerTemplate, cmd); // session = ComputerName; // credential = Credential; } else { invokeCmd = string.Format(localTemplate, cmd); } string version; if (Version == 0) { version = null; } else { version = $"{TfsVersionTable.GetMajorVersion(Version)}.0"; } var result = this.InvokeCommand.InvokeScript(funcCode + invokeCmd, true, PipelineResultTypes.None, null, version, session, credential); WriteObject(result); }
protected override IEnumerable <ServerVersion> DoGetItems() { var tpc = this.GetCollection(); var svc = this.GetService <IRestApiService>(); this.Log("Trying Azure DevOps Services detection logic"); var result = svc.InvokeAsync(tpc, "/").SyncResult(); var html = result.Content.ReadAsStringAsync().GetResult("Error accessing Azure DevOps home page (/)"); var matches = (new Regex(@"""serviceVersion"":""(.+?)( \((.+?)\))?""")).Matches(html); Version version; string versionText = null, longVersion = null; if (matches.Count > 0) { versionText = Regex.Replace(matches[0].Groups[1].Value, "[a-zA-Z]", "") + ".0"; this.Log($"Version text found: '{versionText}'"); version = new Version(versionText); if (matches[0].Groups.Count == 4) { longVersion = $"{matches[0].Groups[1].Value}" + ( !string.IsNullOrEmpty(matches[0].Groups[3].Value)? $" ({matches[0].Groups[3].Value})": "" ); } yield return(new ServerVersion { Version = version, LongVersion = longVersion, Update = version.Minor, FriendlyVersion = "Azure DevOps " + (tpc.IsHosted ? $"Services, Sprint {version.Minor}" : $"Server {TfsVersionTable.GetYear(version.Major)}"), IsHosted = tpc.IsHosted }); yield break; } this.Log("Response does not contain 'serviceVersion' information. Trying TFS detection logic"); result = svc.InvokeAsync(tpc, "/_home/About").GetResult("Error accessing About page (/_home/About) in TFS"); html = result.Content.ReadAsStringAsync().GetResult("Error accessing About page (/_home/About)"); matches = (new Regex(@"\>Version (.+?)\<")).Matches(html); if (matches.Count == 0) { this.Log("Response does not contain 'Version' information"); this.Log($"Returned HTML: {html}"); throw new Exception("Team Foundation Server version not found in response."); } versionText = matches[0].Groups[1].Value; this.Log($"Version text found: '{versionText}'"); version = new Version(versionText); longVersion = $"{version} (TFS {TfsVersionTable.GetYear(version.Major)}))"; yield return(TfsVersionTable.GetServerVersion(version)); }