Created
May 8, 2019 11:38
-
-
Save matiaskorhonen/e176dcc221b7b67151df3168ee9e82af to your computer and use it in GitHub Desktop.
Convert a G Suite CSV to LDIF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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