My Script (basically less information in the csv file) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
'******************************************************************************** ' Description: Exports all distribution lists to CSV '******************************************************************************** dim filename, props filename = "2003DistributionLists.csv" props = array("displayName","sAMAccountName",”Mail”,”mailNickname”) '******************************************************************************** ' Helper Functions '******************************************************************************** function RetrieveUsers() dim rootDse, defaultNamingContext, ldapQuery, ldap, conn, rs set rootDse = GetObject("LDAP://RootDSE") defaultNamingContext = rootDse.Get("defaultNamingContext") ldapQuery = "(&(objectClass=group)(mailNickname=*)(mail=*))" ldap = "<LDAP://" & defaultNamingContext & ">;" & ldapQuery & ";adspath;subtree" set conn = CreateObject("ADODB.Connection") conn.Provider = "ADsDSOObject" conn.Open "Active Directory Provider" set RetrieveUsers = conn.Execute(ldap) end function function ArrayToString(value) dim firstValue, result firstValue = true result = "" for i=0 to UBound(value) if not firstValue then result = result + ";" end if result = result + value(i) firstValue = false next ArrayToString = result end function function DnToEmailAddress(dn) dim ldap, mail mail = "" ldap = "LDAP://" & dn set user = GetObject(ldap) on error resume next mail = user.Get("mail") on error goto 0 DnToEmailAddress = mail end function function Main() dim value, fso, shell, users, firstProp, dns, firstDn, memberEmail, emailAddress set fso = CreateObject("Scripting.FileSystemObject") set csv = fso.CreateTextFile(filename) if not err.number = vbEmpty then msgbox err.message, 0, "ExportError" exit function end If comma = false for each prop in props if comma then csv.Write(",") end if csv.Write("""") csv.Write(prop) csv.Write("""") comma = true next csv.WriteLine(",""memberEmail""") set users = RetrieveUsers() while not users.EOF set user = GetObject(users.Fields(0).Value) memberEmail = "" firstProp = true for each prop in props if not firstProp then csv.Write(",") end if csv.Write("""") value = "" on error resume next value = user.Get(prop) if IsArray(value) then value = ArrayToString(value) if "member" = prop then dns = Split(value, ";") firstDn = true for i=0 to UBound(dns) emailAddress = DnToEmailAddress(dns(i)) if not "" = emailAddress then if not firstDn then memberEmail = memberEmail + ";" end if memberEmail = memberEmail + emailAddress firstDn = false end if next end if end if csv.Write(value) on error goto 0 csv.Write("""") firstProp = false next csv.WriteLine(",""" & memberEmail & """") users.MoveNext wend csv.Close set csv = nothing set fso = nothing Set shell = CreateObject("WScript.Shell") shell.run ("Explorer" & " ." ) end function Main |
Next create a PowerShell command to import the csv file, here’s one I made earlier:
1 2 3 4 |
Import-Csv user2.csv | foreach {New-DistributionGroup -Alias $_.mailnickname -DisplayName $_.displayName -Type Distribution -Name $_.displayName -PrimarySmtpAddress $_.mail -OrganizationalUnit "OU=Users,OU=Sites,DC=DOMAIN,DC=local" } |
Basically the headers from the csv file need to match the sections in the powershell command that start with $_.
Once that runs in powershell without issue then you should be good to import users into the groups….which I also have a script for!!
If you have less than 100 grams carbs day, some protein is used for making glucose in the liver. However with these guidelines you should still get enough. Also I’ve found a number of people feel better with some starchy carbs at most meals, about a fist size. And it frequently improves fat loss when they control their portion of protein / fat.