Skip to content

Instantly share code, notes, and snippets.

@matiaskorhonen
Created May 8, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiaskorhonen/e176dcc221b7b67151df3168ee9e82af to your computer and use it in GitHub Desktop.
Save matiaskorhonen/e176dcc221b7b67151df3168ee9e82af to your computer and use it in GitHub Desktop.
Convert a G Suite CSV to LDIF
require "csv"
csv = CSV.new(File.open("User_Download_08052019_142707.csv"), headers: :first_row)
File.open("./gsuite.ldif", "w+") do |file|
csv.each_with_index do |row, index|
file.write("dn: cn=#{row["First Name [Required]"]} #{row["Last Name [Required]"]},id=#{201 + index}\r\n")
file.write("cn: #{row["First Name [Required]"]} #{row["Last Name [Required]"]}\r\n")
file.write("givenname: -----\r\n")
file.write("mail: #{row["Email Address [Required]"]}\r\n")
file.write("objectclass: top\r\n")
file.write("objectclass: person\r\n")
file.write("\r\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment