Solved

How to create multiple distribution groups in Exchange 2007

Posted on 2010-11-20
23
899 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:3tpro
Comment Utility
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
Comment Utility
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
Comment Utility
And this line is not correct
$members = $group.members -split ":"

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

Author Comment

by:3tpro
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:3tpro
Comment Utility
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
Comment Utility
Yeah that is SP2, can you post the errors you are getting. Maybe the command is not correct.
0
 

Author Comment

by:3tpro
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Is it the same error

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

Expert Comment

by:KenMcF
Comment Utility
replace this line

add-DistributionGroupMember $group $member

with this

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

Author Comment

by:3tpro
Comment Utility
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
Comment Utility
sorry, getting late here. The line should be

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

Expert Comment

by:agentmik
Comment Utility
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
Comment Utility
KenMcF

That worked thanks for your help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
To show how to generate a certificate request 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 Servers >> Certificates…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now