arguments, timeout: $command->timeoutSeconds); $process->run(); return ExchangePowerShellProcessResult::completed( exitCode: $process->getExitCode() ?? 1, stdout: $process->getOutput(), stderr: $process->getErrorOutput(), durationMs: $this->durationMs($startedAt), ); } catch (ProcessTimedOutException) { if ($process instanceof Process && $process->isRunning()) { $process->stop(0); } return ExchangePowerShellProcessResult::timedOut($this->durationMs($startedAt)); } catch (Throwable $exception) { return ExchangePowerShellProcessResult::exception(class_basename($exception), $this->durationMs($startedAt)); } } private function durationMs(float $startedAt): int { return (int) max(0, round((microtime(true) - $startedAt) * 1000)); } }