private void SetWorkingDirectory(PowershellSettings settings) { if (String.IsNullOrEmpty(settings.ComputerName)) { DirectoryPath workingDirectory = _Environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(_Environment); } else if (settings.WorkingDirectory == null) { settings.WorkingDirectory = new DirectoryPath("C:/"); } }
/// <summary> /// Runs `pwsh` against the script and settings provided /// </summary> public void RunScript(string script, PowershellSettings settings) { var pwshSettings = new ToolSettings { WorkingDirectory = settings.WorkingDirectory, ToolTimeout = settings.Timeout == null ? (TimeSpan?)null : new TimeSpan(0, 0, settings.Timeout.Value) }; settings.Arguments.Prepend(script); var args = GetArguments(script); Run(pwshSettings, args); }
private void PowershellCreateCommand(string computer, InstallSettings settings) { //Get Arguments var args = CreateInstallArguments(computer, settings); //Build Script string script = ""; if (!this.ServiceExists(settings.ServiceName, computer)) { //Create script = "& \"sc.exe\" create"; } else { //Config script = "& \"sc.exe\" config"; } //Create Settings PowershellSettings powerSettings = new PowershellSettings() { FormatOutput = true, LogOutput = true, OutputToAppConsole = settings.OutputToAppConsole, Arguments = args }; //Remote Connection if (!String.IsNullOrEmpty(computer)) { powerSettings.ComputerName = computer; } this.SetWorkingDirectory(powerSettings); //Run Powershell _PowershellRunner.Start(script, powerSettings); }
//Helpers private void PowershellCreateCommand(string computer, InstallSettings settings) { //Get Arguments ProcessArgumentBuilder args = new ProcessArgumentBuilder(); string pathArgs = settings.Arguments.Render(); this.SetFilePath(computer, settings); if (!String.IsNullOrEmpty(settings.ServiceName)) { args.AppendQuoted(settings.ServiceName); } if (string.IsNullOrEmpty(pathArgs)) { args.AppendQuoted("binPath", settings.ExecutablePath.FullPath); } else { args.AppendQuoted("binPath", "\\\"" + settings.ExecutablePath.FullPath + "\\\" " + pathArgs.Replace("\"", "\\\"")); } if (!String.IsNullOrEmpty(settings.DisplayName)) { args.AppendQuoted("DisplayName", settings.DisplayName); } if (!String.IsNullOrEmpty(settings.Dependencies)) { args.AppendQuoted("depend", settings.Dependencies); } if (!String.IsNullOrEmpty(settings.StartMode)) { args.AppendQuoted("start", settings.Dependencies); } if (!String.IsNullOrEmpty(settings.Username)) { args.AppendQuoted("obj", settings.Username); } if (!String.IsNullOrEmpty(settings.Password)) { args.AppendQuotedSecret("password", settings.Password); } //Build Script string script = ""; if (!this.ServiceExists(settings.ServiceName, computer)) { //Create script = "& \"sc.exe\" create"; } else { //Config script = "& \"sc.exe\" config"; } //Create Settings PowershellSettings powerSettings = new PowershellSettings() { FormatOutput = true, LogOutput = true, Arguments = args }; //Remote Connection if (!String.IsNullOrEmpty(computer)) { powerSettings.ComputerName = computer; } this.SetWorkingDirectory(powerSettings); //Run Powershell _PowershellRunner.Start(script, powerSettings); }