Powershell – Exchange Powershell – Creating Distribution Groups

exchange-2010powershell

I'm trying to add some new distribution lists to exchange using the below.

 C:\>Import-CSV "c:\external.csv" | foreach {New-DistributionGroup -Name $_.name -Type $_.Type}

I've created a CSV file in the format

Name,         Type
Inter_Partners, Distribution

When I run the above command I get the following:

A positional parameter cannot be found that accepts argument '-Type'.

enter image description here

What is missing from the syntax to get these created.?

Best Answer

I can't test this since I'm not at work today but you're missing the parameters in both the csv and the cmdlet, as far as I can see, so you're just chucking a bunch of data at the cmdlet without specifying what to do with it.

Your CSV file needs to look something like this:

Name, Type
Group1, Distribution
Group2, Distribution

And the powershell command needs to specify the arguments as follows:

Import-CSV "c:\example.csv" | foreach {New-DistributionGroup -Name $_.Name -Type $_.Type}

I actually logged into a test system at work to check my thoughts in response to your continuing problems. Here are the results of running the statement I'm using against my example .csv file for me:

[PS] C:\Windows\system32>import-csv "e:\test.txt" | foreach {New-DistributionGroup -Name $_.Name -Type $_.Type}

Name                          DisplayName                   GroupType                     PrimarySmtpAddress
----                          -----------                   ---------                     ------------------
test1                         test1                         Universal                     test11@example.com
test2                         test2                         Universal                     test21@example.com

There's more information in the technet exchange reference guide if you need it.