Solved

How to create multiple distribution groups in Exchange 2007

Posted on 2010-11-20
23
913 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
In this video we show how to create an Accepted Domain 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 >> Ac…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

688 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