code: private File createWriteTempFile(BufferedReader srcReader) {
  
          BufferedWriter tmpWriter = null;
          File tmpFile = null;
  
          try {
              tmpFile = File.createTempFile("psscript_" + new Date().getTime(), ".ps1", this.tempFolder);
              if (!tmpFile.exists()) {
                  return null;
              }
  
              tmpWriter = new BufferedWriter(new FileWriter(tmpFile));
              String line;
              while (srcReader != null && (line = srcReader.readLine()) != null) {
                  tmpWriter.write(line);
                  tmpWriter.newLine();
              }
  
              // Add end script line
              tmpWriter.write("Write-Output \"" + END_SCRIPT_STRING + "\"");
          } catch (IOException ioex) {
              logger.log(Level.SEVERE,
                      "Unexpected error while writing temporary PowerShell script", ioex);
          } finally {
              try {
                  if (tmpWriter != null) {
                      tmpWriter.close();
                  }
              } catch (IOException ex) {
                  logger.log(Level.SEVERE,
                          "Unexpected error when processing temporary PowerShell script", ex);
              }
          }
  
          return tmpFile;
      }
docs: Writes a temp powershell script file based on the srcReader