public async Task <List <ActionResult> > Execute(DeploymentTaskExecutionParams execParams) { var validation = await Validate(execParams); if (validation.Any()) { return(validation); } var script = Helpers.ReadStringResource(SCRIPT_NAME); var certRequest = execParams.Subject as CertificateRequestResult; execParams.Log?.Information("Executing command via PowerShell"); var services = execParams.Settings.Parameters.FirstOrDefault(p => p.Key == "services")?.Value; var doNotRequireSsl = execParams.Settings.Parameters.FirstOrDefault(p => p.Key == "donotrequiressl")?.Value; var parameters = new Dictionary <string, object> { { "services", services }, { "addDoNotRequireSslFlag", doNotRequireSsl } }; var scriptResult = await PowerShellManager.RunScript(execParams.Context.PowershellExecutionPolicy, certRequest, parameters : parameters, scriptContent : script, credentials : execParams.Credentials); return(new List <ActionResult> { scriptResult }); }
private async void TestScript_Click(object sender, EventArgs e) { var button = (Button)sender; string scriptFile = null; var result = new CertificateRequestResult { ManagedItem = MainViewModel.SelectedItem, IsSuccess = true, Message = "Script Testing Message" }; if (button.Name == "Button_TestPreRequest") { scriptFile = MainViewModel.SelectedItem.RequestConfig.PreRequestPowerShellScript; result.IsSuccess = false; // pre-request messages will always have IsSuccess = false } else if (button.Name == "Button_TestPostRequest") { scriptFile = MainViewModel.SelectedItem.RequestConfig.PostRequestPowerShellScript; } if (string.IsNullOrEmpty(scriptFile)) { return; // don't try to run empty script } try { string scriptOutput = await PowerShellManager.RunScript(result, scriptFile); MessageBox.Show(scriptOutput, "Powershell Output", MessageBoxButton.OK, MessageBoxImage.Information); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Script Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task <List <ActionResult> > Execute(DeploymentTaskExecutionParams execParams) { var validation = await Validate(execParams); if (validation.Any()) { return(validation); } var script = Helpers.ReadStringResource(SCRIPT_NAME); var definition = execParams.Definition; definition = GetDefinition(definition); var certRequest = execParams.Subject as CertificateRequestResult; execParams.Log?.Information("Executing command via PowerShell"); var performRestart = execParams.Settings.Parameters.FirstOrDefault(p => p.Key == "performServiceRestart")?.Value ?? "false"; var alternateTlsBinding = execParams.Settings.Parameters.FirstOrDefault(p => p.Key == "alternateTlsBinding")?.Value ?? "false"; var parameters = new Dictionary <string, object> { { "performServiceRestart", performRestart }, { "alternateTlsBinding", alternateTlsBinding } }; var scriptResult = await PowerShellManager.RunScript(execParams.Context.PowershellExecutionPolicy, certRequest, parameters : parameters, scriptContent : script, credentials : execParams.Credentials); return(new List <ActionResult> { scriptResult }); }
public async Task <ActionResult> DeleteRecord(DnsRecord request) { var scriptContent = PrepareScript("Remove-DnsTxt", request.RecordName, request.RecordValue); var objParams = _parameters.ToDictionary(p => p.Key, p => p.Value as object); return(await PowerShellManager.RunScript(null, null, objParams, scriptContent, null, _scriptExecutionPolicy)); }
/// <summary> /// Execute a local powershell script /// </summary> /// <param name="log"></param> /// <param name="managedCert"></param> /// <param name="settings"></param> /// <param name="credentials"></param> /// <param name="isPreviewOnly"></param> /// <returns></returns> public async Task <List <ActionResult> > Execute(DeploymentTaskExecutionParams execParams) { var results = new List <ActionResult>(); var certRequest = execParams.Subject as CertificateRequestResult; var command = execParams.Settings.Parameters.FirstOrDefault(c => c.Key == "scriptpath")?.Value; var args = execParams.Settings.Parameters.FirstOrDefault(c => c.Key == "args")?.Value; var inputResultAsArgument = execParams.Settings.Parameters.FirstOrDefault(c => c.Key == "inputresult")?.Value; var parameters = new Dictionary <string, object>(); if (inputResultAsArgument?.Trim().ToLower() == "true") { parameters.Add("result", certRequest); } ; if (!string.IsNullOrEmpty(args)) { foreach (var o in args.Split(';')) { if (!string.IsNullOrEmpty(o)) { var keyValuePair = o.Split('='); if (keyValuePair.Length == 1) { // item has a key only parameters.Add(keyValuePair[0].Trim(), ""); } else { // item has a key and value parameters.Add(keyValuePair[0].Trim(), keyValuePair[1].Trim()); } } } } execParams.Log?.Information("Executing command via PowerShell"); string logonType = execParams.Settings.Parameters.FirstOrDefault(c => c.Key == "logontype")?.Value ?? null; // if running as local/default service user no credentials are provided for user impersonation var credentials = execParams.Settings.ChallengeProvider == StandardAuthTypes.STANDARD_AUTH_LOCAL ? null : execParams.Credentials; var result = await PowerShellManager.RunScript(execParams.Context.PowershellExecutionPolicy, null, command, parameters, null, credentials : credentials, logonType : logonType); results.Add(result); return(results); }
public async Task TestLoadManagedCertificates() { var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); await PowerShellManager.RunScript(new CertificateRequestResult {}, path + "\\Assets\\Powershell\\Simple.ps1"); var transcriptLogExists = System.IO.File.Exists(@"C:\Temp\Certify\TestOutput\TestTranscript.txt"); var outputExists = System.IO.File.Exists(@"C:\Temp\Certify\TestOutput\TestPSOutput.txt"); Assert.IsTrue(outputExists, "Powershell output file should exist"); Assert.IsTrue(transcriptLogExists, "Powershell transcript log file should exist"); System.IO.File.Delete(@"C:\Temp\Certify\TestOutput\TestPSOutput.txt"); System.IO.File.Delete(@"C:\Temp\Certify\TestOutput\TestTranscript.txt"); }
public async Task TestLoadManagedCertificates() { var path = AppContext.BaseDirectory; await PowerShellManager.RunScript("Unrestricted", new CertificateRequestResult { }, System.IO.Path.Combine(path, "Assets\\Powershell\\Simple.ps1")); var transcriptLogExists = System.IO.File.Exists(@"C:\Temp\Certify\TestOutput\TestTranscript.txt"); var outputExists = System.IO.File.Exists(@"C:\Temp\Certify\TestOutput\TestPSOutput.txt"); Assert.IsTrue(outputExists, "Powershell output file should exist"); Assert.IsTrue(transcriptLogExists, "Powershell transcript log file should exist"); try { System.IO.File.Delete(@"C:\Temp\Certify\TestOutput\TestPSOutput.txt"); System.IO.File.Delete(@"C:\Temp\Certify\TestOutput\TestTranscript.txt"); } catch { } }
public async Task <List <ActionResult> > Execute(DeploymentTaskExecutionParams execParams) { var validation = await Validate(execParams); if (validation.Any()) { return(validation); } var script = Helpers.ReadStringResource(SCRIPT_NAME); var certRequest = execParams.Subject as CertificateRequestResult; execParams.Log?.Information("Executing command via PowerShell"); var parameters = new Dictionary <string, object>(); var scriptResult = await PowerShellManager.RunScript(execParams.Context.PowershellExecutionPolicy, certRequest, parameters : parameters, scriptContent : script, credentials : execParams.Credentials); return(new List <ActionResult> { scriptResult }); }