public override Task ExecuteAsync(IOperationExecutionContext context) { if (context.Simulation) { this.LogInformation("Executing PowerShell Script..."); return(Complete); } var fullScriptName = this.DefaultArgument.AsString(); if (fullScriptName == null) { this.LogError("Bad or missing script name."); return(Complete); } return(PSUtil.ExecuteScriptAsync( logger: this, context: context, fullScriptName: fullScriptName, arguments: this.NamedArguments, outArguments: this.OutArguments, collectOutput: false, progressUpdateHandler: (s, e) => Interlocked.Exchange(ref this.currentProgress, e) )); }
public override async Task <PersistedConfiguration> CollectAsync(IOperationCollectionContext context) { if (!this.ValidateConfiguration()) { return(null); } ExecutePowerShellJob.Result result; if (!string.IsNullOrWhiteSpace(this.CollectScriptAsset)) { result = await PSUtil.ExecuteScriptAsync( logger : this, context : context, fullScriptName : this.CollectScriptAsset, arguments : this.CollectScriptParams ?? new Dictionary <string, RuntimeValue>(), outArguments : new Dictionary <string, RuntimeValue>(), collectOutput : !this.UseExitCode, progressUpdateHandler : (s, e) => Interlocked.Exchange(ref this.currentProgress, e) ); } else { var jobRunner = context.Agent.GetService <IRemoteJobExecuter>(); var job = new ExecutePowerShellJob { ScriptText = this.CollectScript, DebugLogging = this.DebugLogging, VerboseLogging = this.VerboseLogging, CollectOutput = !this.UseExitCode, LogOutput = this.UseExitCode, Variables = PowerShellScriptRunner.ExtractVariables(this.CollectScript, context) }; job.MessageLogged += (s, e) => this.Log(e.Level, e.Message); job.ProgressUpdate += (s, e) => Interlocked.Exchange(ref this.currentProgress, e); result = await jobRunner.ExecuteJobAsync(job, context.CancellationToken) as ExecutePowerShellJob.Result; } if (result.ExitCode != null) { this.LogDebug("Script exit code: " + result.ExitCode); } return(new KeyValueConfiguration { Key = this.ConfigurationKey, Value = this.UseExitCode ? result.ExitCode?.ToString() : string.Join(", ", result.Output) }); }
public override async Task ConfigureAsync(IOperationExecutionContext context) { if (!this.ValidateConfiguration()) { return; } _ = await PSUtil.ExecuteScriptAsync( logger : this, context : context, scriptNameOrContent : AH.CoalesceString(this.ConfigureScriptAsset, this.ConfigureScript), scriptIsAsset : !string.IsNullOrWhiteSpace(this.ConfigureScriptAsset), arguments : this.ConfigureScriptParams ?? new Dictionary <string, RuntimeValue>(), outArguments : new Dictionary <string, RuntimeValue>(), collectOutput : false, progressUpdateHandler : (s, e) => Interlocked.Exchange(ref this.currentProgress, e) ); }
public override async Task <PersistedConfiguration> CollectAsync(IOperationCollectionContext context) { if (!this.ValidateConfiguration()) { return(null); } var result = await PSUtil.ExecuteScriptAsync( logger : this, context : context, scriptNameOrContent : AH.CoalesceString(this.CollectScriptAsset, this.CollectScript), scriptIsAsset : !string.IsNullOrWhiteSpace(this.CollectScriptAsset), arguments : this.CollectScriptParams ?? new Dictionary <string, RuntimeValue>(), outArguments : new Dictionary <string, RuntimeValue>(), collectOutput : !this.UseExitCode, progressUpdateHandler : (s, e) => Interlocked.Exchange(ref this.currentProgress, e) ); return(new KeyValueConfiguration { Key = this.ConfigurationKey, Value = this.UseExitCode ? result.ExitCode?.ToString() : string.Join(", ", result.Output) }); }