Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hokkai7go/fa1d716317e21f1f7816ecb5b67c5247 to your computer and use it in GitHub Desktop.
Save hokkai7go/fa1d716317e21f1f7816ecb5b67c5247 to your computer and use it in GitHub Desktop.
require "csv"
azuread_csv =
CSV.foreach("GoogleUserList.csv") do |r|
# google csv format
# First Name [Required],Last Name [Required],Email Address [Required],Password [Required],Password Hash Function [UPLOAD ONLY],Org Unit Path [Required],New Primary Email [UPLOAD ONLY],Status [READ ONLY],Last Sign In [READ ONLY],Recovery Email,Home Secondary Email,Work Secondary Email,Recovery Phone [MUST BE IN THE E.164 FORMAT],Work Phone,Home Phone,Mobile Phone,Work Address,Home Address,Employee ID,Employee Type,Employee Title,Manager Email,Department,Cost Center,2sv Enrolled [READ ONLY],2sv Enforced [READ ONLY],Building ID,Floor Name,Floor Section,Email Usage [READ ONLY],Drive Usage [READ ONLY],Photos Usage [READ ONLY],Storage limit [READ ONLY],Storage Used [READ ONLY],Change Password at Next Sign-In,New Status [UPLOAD ONLY],Advanced Protection Program enrollment
# skip header
if r[0].include?('First Name [Required]')
google_firstname = r[0]
google_lastname = r[1]
google_email = r[2]
google_password = r[3]
google_pass_hash = r[4]
google_org_unit = r[5]
google_primary_email = r[6]
google_status = r[7]
google_last_signin = r[8]
google_recovery_email = r[9]
google_home_2nd_email = r[10]
google_work_2nd_email = r[11]
google_recovery_phone = r[12]
google_work_phone = r[13]
google_home_phone = r[14]
google_mobile_phone = r[15]
google_work_address = r[16]
google_home_address = r[17]
google_employeeid = r[18]
google_employeetype = r[19]
google_employeetitle = r[20]
google_manager_email = r[21]
google_department = r[22]
google_cost_center = r[23]
azuread_displayName = google_lastname + " " + google_firstname
azuread_userPrincipalName = google_email
azuread_passwordProfile = "<password>"
azuread_accountEnabled = "No"
azuread_givenName = google_firstname
azuread_surname = google_lastname
azuread_jobTitle = "" #google_employeetitle
azuread_department = "" #google_department
azuread_usageLocation = "Japan"
azuread_streetAddress = ""
azuread_state = ""
azuread_country = "Japan"
azuread_physicalDeliveryOfficeName = ""
azuread_city = ""
azuread_postalCode = ""
azuread_telephoneNumber = "" #google_work_phone
azuread_mobile = "" #google_mobile_phone
azuread_csv << ["#{azuread_displayName}", "#{azuread_userPrincipalName}", "#{azuread_passwordProfile}", "#{azuread_accountEnabled}", "#{azuread_givenName}", "#{azuread_surname}", "#{azuread_jobTitle}", "#{azuread_department}", "#{azuread_usageLocation}", "#{azuread_streetAddress}", "#{azuread_state}", "#{azuread_country}", "#{azuread_physicalDeliveryOfficeName}", "#{azuread_city}", "#{azuread_postalCode}", "#{azuread_telephoneNumber}", "#{azuread_mobile}"]
header ='azuread_header.csv').chomp
rows ='data.csv').chomp
table = CSV.parse(<<CSV, headers: true)
File.write('azuread_userlist.csv', table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment