code: public static PowerShellResponse executeSingleCommand(String command) {
          PowerShellResponse response = null;
  
          try (PowerShell session = PowerShell.openSession()) {
              response = session.executeCommand(command);
          } catch (PowerShellNotAvailableException ex) {
              logger.log(Level.SEVERE, "PowerShell not available", ex);
          }
  
          return response;
      }
docs: Execute a single command in PowerShell console and gets result
  
  @param command the command to execute
  @return response with the output of the command