How to create multiple distribution groups in Exchange 2007

I have over 200 distribution groups to create within a Exchange 2007 organization.
I have read some examples on the forums like this one: http://social.technet.microsoft.com/Forums/en/exchangesvrgeneral/thread/0f86bb8a-63a2-44e5-921f-4a227221e71d


But I am still having issues getting the command to run successfully. Getting ‘name’ null error message.
Can someone give me a example of what a CSV file should look like with my example information below.

Group Name = Group 1234
Type = Universal Distribuiton
SAM = group1234
Members = member1,member2,member3,member4
 
I need to be able to know what commands to use and the correct way to do a CSV file so I can create several different groups at once.
3tproAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
KenMcFConnect With a Mentor Commented:
sorry, getting late here. The line should be

add-DistributionGroupMember -identity $group.name -member $member
0
 
KenMcFCommented:
You could do something like this since there are multiple members. I am sure there is a better way but this should work.

CSV File newgroups.csv, note the ; between members
----------------------------
GroupName,Type,SAM,Members
Group1234,Distribuiton,group1234,member1;member2;member3;member4
------------------------------

$NewGroups = Import-CSV "C:\NewGroups.csv"
foreach($Group in $NewGroups){
New-DistributionGroup -Name $_.name -OrganizationalUnit "contoso.com/Users" -SAMAccountName $_.SamName -Type $_.Type
$members = $group.members -split ":"
foreach($member in $members){
add-DistributionGroupMember $group $member
}
}
0
 
3tproAuthor Commented:
I created the csv file just like you suggested and ran this command directly in Exchange shell with my information filled in:

$NewGroups = Import-CSV "C:\NewGroups.csv"
foreach($Group in $NewGroups){
New-DistributionGroup -Name $_.name -OrganizationalUnit "contoso.com/Users" -SAMAccountName $_.SamName -Type $_.Type
$members = $group.members -split ":"
foreach($member in $members){
add-DistributionGroupMember $group $member
}
}


I get this error:
You must provide a value expression on the right-hand side of the '-' operator.
At line:3 char:28
+ $members = $group.members -s <<<< plit ":"
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
KenMcFCommented:
Sorry, forgot to change the text that line should be, you will also need to change the OU it will get created in. And this may get truncated, this comamnd is a single line

New-DistributionGroup -Name $Group.name -OrganizationalUnit "contoso.com/Users" -SAMAccountName $Group.SamName -Type $Group.Type
0
 
3tproAuthor Commented:
Still getting that same error.

You must provide a value expression on the right-hand side of the '-' operator.
At line:3 char:28
+ $members = $group.members -s <<<< plit ":"


 Maybe you can see what is wrong with my info. Here is my stuff exactly.
And I assume I don't need to use .ps1 file to run this.

shell:
$NewGroups = Import-CSV "C:\groups\NewGroups.csv"
foreach($Group in $NewGroups){
New-DistributionGroup -Name $Group.name -OrganizationalUnit "mydomain.local/NY Groups" -SAMAccountName $Group.SamName -Type $Group.Type
$members = $group.members -split ":"
foreach($member in $members){
add-DistributionGroupMember $group $member
}
}



CSV:

GroupName,Type,SAM,Members
GreenTeam,Distribuiton,user1,user2;user3;user4
0
 
KenMcFCommented:
Sorry, this was my fault for not paying close enought attention to the csv header and the code. The variables need to match the header of the csv.

GroupName,Type,SAM,Members
 
$NewGroups = Import-CSV "C:\groups\NewGroups.csv"
foreach($Group in $NewGroups){
New-DistributionGroup -Name $Group.groupname -OrganizationalUnit "mydomain.local/NY Groups" -SAMAccountName $Group.Sam -Type $Group.Type
$members = $group.members -split ":"
foreach($member in $members){
add-DistributionGroupMember $group $member
}
}

Open in new window

0
 
KenMcFCommented:
And this line is not correct
$members = $group.members -split ":"

it should be
$members = $group.members -split ";"
0
 
3tproAuthor Commented:
Thanks for all the help but I'm still getting this error after applying the corrections.

You must provide a value expression on the right-hand side of the '-' operator.
At line:3 char:28
+ $members = $group.members -s <<<< plit ";"
0
 
KenMcFCommented:
Check your csv file
GreenTeam,Distribuiton,user1,user2;user3;user4
should be
GreenTeam,Distribuiton,user1;user2;user3;user4

and run this to see the output

 
$NewGroups = Import-CSV "C:\groups\NewGroups.csv"  
foreach($Group in $NewGroups){  
$members = $group.members -split ";"  
foreach($member in $members){  
$member  
}  
}

Open in new window

0
 
3tproAuthor Commented:
My CSV file is as follows:

Name,Type,SAM,Members
GreenTeam,Distribuiton,greenteam,user1;user2;user3;user4



I ran this:

$NewGroups = Import-CSV "C:\groups\NewGroups.csv"  
foreach($Group in $NewGroups){  
$members = $group.members -split ";"  
foreach($member in $members){  
$member  
}  
}



and get this:

You must provide a value expression on the right-hand side of the '-' operator.
At line:2 char:28
+ $members = $group.members -s <<<< plit ";"
0
 
KenMcFCommented:
I think you are running version 1 of powershell.

What serivce pack are you running on exchange?

If you are running SP2 you can update powershell to version 2

http://support.microsoft.com/kb/968929
0
 
3tproAuthor Commented:
I am using PowerShell version 1.
I'm on SP2 for Exchange.
Just installed PS 2 but it wants a reboot so will see if that can happen.
0
 
3tproAuthor Commented:
Now after installing power shell 2 when i run the command i get tons of errors.
From the information i see i think im on Exchange SP2. My Build number = 8.2   176.2
0
 
KenMcFCommented:
Yeah that is SP2, can you post the errors you are getting. Maybe the command is not correct.
0
 
3tproAuthor Commented:
It is this error repeating several times:

New-DistributionGroup : Cannot bind argument to parameter 'Name' because it is
null.
At line:2 char:28
+ New-DistributionGroup -Name <<<<  $Group.groupname -OrganizationalUnit "mydomain.local/NY Groups" -SAMAccountName $Group.Sam -Type $Group.Type
    + CategoryInfo          : InvalidData: (:) [New-DistributionGroup], Parame
   terBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.Exchange.Management.RecipientTasks.NewDistributionGroup

Add-DistributionGroupMember : Cannot bind parameter 'Identity'. Cannot convert
the "@{Name=GreenTeam; Type=Distribuiton; SAM=greenteam; Members=user1;user2;user3;user4;user5}" value of type "System.Management.Automation.PSCus
tomObject" to type "Microsoft.Exchange.Configuration.Tasks.DistributionGroupIdP
arameter".
At line:5 char:28
+ add-DistributionGroupMember <<<<  $group $member
    + CategoryInfo          : InvalidArgument: (:) [Add-DistributionGroupMembe
   r], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchang
   e.Management.RecipientTasks.AddDistributionGroupMember
0
 
KenMcFCommented:
What is in your csv header, it looks like going through the thread it may have changed.
is it groupname  or name.

if it is groupname
$Group.groupname

if it is Name
$Group.name



0
 
3tproAuthor Commented:
confirmed and still not working. getting the same bunch of errors as posted previously.

csv file exactly:

Name,Type,SAM,Members
GreenTeam,Distribuiton,greenteam,user1;user2;user3;user4



command im running:

$NewGroups = Import-CSV "C:\groups\NewGroups.csv"
foreach($Group in $NewGroups){
New-DistributionGroup -Name $Group.name -OrganizationalUnit "mydomain.local/NY Groups" -SAMAccountName $Group.Sam -Type $Group.Type
$members = $group.members -split ";"
foreach($member in $members){
add-DistributionGroupMember $group $member
}
}
0
 
3tproAuthor Commented:
Even with those errors it actually did create the groups but without the members in them. I am only testing with 2 groups at a time so id like to get it down were it will add the members also.
0
 
KenMcFCommented:
Is it the same error

+ New-DistributionGroup -Name <<<< 
0
 
KenMcFCommented:
replace this line

add-DistributionGroupMember $group $member

with this

add-DistributionGroupMember -identity $group -member $member
0
 
3tproAuthor Commented:
It again was able to create the groups but not add the members. It gave this error after each group creation:

Add-DistributionGroupMember : Cannot bind parameter 'Identity'. Cannot convert
the "@{Name=2596.00; Type=Distribution; SAM=2596.00; Members=user1;user2}"
 value of type "System.Management.Automation.PSCustomObject" to type "Microsoft
.Exchange.Configuration.Tasks.DistributionGroupIdParameter".
At line:5 char:38
+ add-DistributionGroupMember -identity <<<<  $group -member $member
    + CategoryInfo          : InvalidArgument: (:) [Add-DistributionGroupMembe
   r], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchang
   e.Management.RecipientTasks.AddDistributionGroupMember

Add-DistributionGroupMember : Cannot bind parameter 'Identity'. Cannot convert
the "@{Name=2596.00; Type=Distribution; SAM=2596.00; Members=user1;user2}"
 value of type "System.Management.Automation.PSCustomObject" to type "Microsoft
.Exchange.Configuration.Tasks.DistributionGroupIdParameter".
At line:5 char:38
+ add-DistributionGroupMember -identity <<<<  $group -member $member
    + CategoryInfo          : InvalidArgument: (:) [Add-DistributionGroupMembe
   r], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchang
   e.Management.RecipientTasks.AddDistributionGroupMember
0
 
Mohammad Ishtyaq KhatriCommented:
Hi,

The question us asked was already been answered on Experts-Exchange.
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_23357229.html

Thanks,
AgentMIK
0
 
3tproAuthor Commented:
KenMcF

That worked thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.