Solved

How to create multiple distribution groups in Exchange 2007

Posted on 2010-11-20
23
908 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:3tpro
  • 11
  • 11
23 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181541
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
 

Author Comment

by:3tpro
ID: 34181602
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181620
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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

Author Comment

by:3tpro
ID: 34181686
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181733
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181735
And this line is not correct
$members = $group.members -split ":"

it should be
$members = $group.members -split ";"
0
 

Author Comment

by:3tpro
ID: 34181761
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181781
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
 

Author Comment

by:3tpro
ID: 34181812
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181836
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
 

Author Comment

by:3tpro
ID: 34181866
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
 

Author Comment

by:3tpro
ID: 34181958
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181962
Yeah that is SP2, can you post the errors you are getting. Maybe the command is not correct.
0
 

Author Comment

by:3tpro
ID: 34181988
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34181997
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
 

Author Comment

by:3tpro
ID: 34182021
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
 

Author Comment

by:3tpro
ID: 34182027
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 34182033
Is it the same error

+ New-DistributionGroup -Name <<<< 
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34182035
replace this line

add-DistributionGroupMember $group $member

with this

add-DistributionGroupMember -identity $group -member $member
0
 

Author Comment

by:3tpro
ID: 34182058
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
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 34182071
sorry, getting late here. The line should be

add-DistributionGroupMember -identity $group.name -member $member
0
 
LVL 8

Expert Comment

by:Mohammad Ishtyaq Khatri
ID: 34182072
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
 

Author Comment

by:3tpro
ID: 34182100
KenMcF

That worked thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
This video discusses moving either the default database or any database to a new volume.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question