diff --git a/ActiveDirectoryQuerier/PowerShell/PSExecutor.cs b/ActiveDirectoryQuerier/PowerShell/PSExecutor.cs index 0fe91cc..c49d7c0 100644 --- a/ActiveDirectoryQuerier/PowerShell/PSExecutor.cs +++ b/ActiveDirectoryQuerier/PowerShell/PSExecutor.cs @@ -40,12 +40,19 @@ public PSOutput Execute(Command psCommand, OutputFormat outputFormat = OutputFor public async Task ExecuteAsync(Command command, OutputFormat outputFormat = OutputFormat.Text) { - _powerShell.Commands.Clear(); - AssembleFullCommand(command, outputFormat); + try + { + _powerShell.Commands.Clear(); + AssembleFullCommand(command, outputFormat); - PSDataCollection results = await _powerShell.InvokeAsync(); + PSDataCollection results = await _powerShell.InvokeAsync(); - return ProcessExecutionResults(results); + return ProcessExecutionResults(results); + } + catch (Exception exception) + { + return HandleExecutionException(exception); + } } private void AssembleFullCommand(Command psCommand, OutputFormat outputFormat)