# Cannot bind argument to parameter 'Name' because it is an empty string.

**URL:** <https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583>\
**Category:** PowerShell Help\
**Created:** [November 23, 2016, 8:39am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583 "2016-11-23T08:39:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![frshell](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@frshell](https://forums.powershell.org/u/frshell)\
**Post date:** [November 23, 2016, 8:39am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/1 "2016-11-23T08:39:03Z")

</div>

Hi everybody,

I try to script for office 365 adding distribution groups and then add users later.  
But my code does not work until the end … (I learn the powershell …)

> # #$icsv = "C:\Users\xxxxxx\Desktop\distribution csv\Import\_Name\_Distribution.csv" #$member = "C:\Users\xxxxxx\Desktop\distribution csv\Import\_memberDistr.csv" # ######################## # Import CSV $filepath1 = "C:\Users\xxxxxx\Desktop\distribution csv\Import\_Name\_Distribution2.csv" $users = import-csv $filepath1 # add domain $users = foreach-Object {$\_.name} $domain = "@DOMAIN.FR" $PSmtpAddress = $\_.name + $domain # Script variable $users | ForEach-Object { New-DistributionGroup -Name $\_.name -Type $\_.type -PrimarySmtpAddress $PSmtpAddress | Set-DistributionGroup -RequireSenderAuthenticationEnabled $False }

Thanks for your’ help 🙂

---

<div class="post-metadata">

**Author:** ![matt-mcnabb](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-mcnabb](https://forums.powershell.org/u/matt-mcnabb)\
**Post date:** [November 23, 2016, 8:43am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/2 "2016-11-23T08:43:04Z")

</div>

You’re passing in the “name” property of the $users, which is imported from a CSV file. Are you certain that the CSV file contains a header called name? If it does, are there rows which do not contain a value in that column? The error indicates that $\_.name is causing the issue.

---

<div class="post-metadata">

**Author:** ![frshell](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@frshell](https://forums.powershell.org/u/frshell)\
**Post date:** [November 23, 2016, 8:48am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/3 "2016-11-23T08:48:09Z")

</div>

Thanks for replies 🙂  
yes, sure !

my csv :

```
name,type
xxxxx,Distribution
xxxxx,Distribution
xxxxx,Distribution
xxxxx,Distribution
```

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 23, 2016, 9:21am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/4 "2016-11-23T09:21:47Z")

</div>

Give this a try (Note: You will need to remove the -WhatIf to perform the update after you test):

```
#	Import CSV
$filepath1 = "C:\Users\xxxxxx\Desktop\distribution csv\Import_Name_Distribution2.csv"
$users = import-csv $filepath1

foreach ($user in $users) {
    $params = @{
         Name = $user.Name 
         Type = $user.Type 
         PrimarySmtpAddress = "{0}@DOMAIN.FR" -f $user.Name
    }
    
    New-DistributionGroup @params | 
    Set-DistributionGroup -RequireSenderAuthenticationEnabled $False -WhatIf
}
```

---

<div class="post-metadata">

**Author:** ![frshell](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@frshell](https://forums.powershell.org/u/frshell)\
**Post date:** [November 23, 2016, 9:59am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/5 "2016-11-23T09:59:05Z")

</div>

Ohhhh thanks, good !

A another reply by technet :

```
$filepath1 = "C:\Users\xxxxxx\Desktop\distribution csv\Import_Name_Distribution2.csv"
Import-Csv $filepath1 | Foreach {
    $PSmtpAddress = $_.name + '@DOMAIN.FR'
    New-DistributionGroup -Name $_.name -Type $_.type -PrimarySmtpAddress $PSmtpAddress | 
        Set-DistributionGroup -RequireSenderAuthenticationEnabled $False
}
```

Why my code doesn’t work ? (sorry for my english)

Whats difference between this code ?

Thansk ! 🙂

---

<div class="post-metadata">

**Author:** ![albert-van-boerum](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albert-van-boerum/32/499_2.png) [@albert-van-boerum](https://forums.powershell.org/u/albert-van-boerum)\
**Post date:** [November 23, 2016, 10:15am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/6 "2016-11-23T10:15:55Z")

</div>

Can you try to replace the foreach with ForEach-Object

If this does not work, What is the error?

---

<div class="post-metadata">

**Author:** ![frshell](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@frshell](https://forums.powershell.org/u/frshell)\
**Post date:** [November 23, 2016, 10:26am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/7 "2016-11-23T10:26:43Z")

</div>

it is already ForEach-Object

I have try with for each in à precedent script and doesnt 'work agin. But i progress ^^

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 23, 2016, 10:41am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/8 "2016-11-23T10:41:54Z")

</div>

A couple of problems:

- This line overwrites your CSV: $users = foreach-Object {$\_.name}. When you attempt to reference $\_.Type, it would not exist. It actually converts it to an array of computers "Computer1", Computer2"....
- This line is outside of your loop: $PSmtpAddress = $\_.name + $domain. This means that it has no idea what $\_.Name is, but as it's outside the loop the value would not change. So, if it resolved the $\_.Name to Computer1 and then you loop through Computer1 and Computer2, when you loop to Computer2 it would still be using Computer1 because it's not resolved in the loop. See the example below

```
$computers = "Computer1", "Computer2"

#Here, we reference computer, so we create the $computer
#variable in the loop, so it has no idea what $computer is
$PSmtpAddress = "{0}@domain.fr" -f $computer

foreach ($computer in $computers) {
    $PSmtpAddress
}
```

Output:

```
@domain.fr
@domain.fr
```

Now try this code:

```
$computers = "Computer1", "Computer2"

foreach ($computer in $computers) {
    $PSmtpAddress = "{0}@domain.fr" -f $computer
    $PSmtpAddress
}
```

Output:

```
Computer1@domain.fr
Computer2@domain.fr
```

---

<div class="post-metadata">

**Author:** ![frshell](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@frshell](https://forums.powershell.org/u/frshell)\
**Post date:** [November 24, 2016, 5:10am UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/9 "2016-11-24T05:10:17Z")

</div>

Hi,

Thanks you for this. I progress

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/cannot-bind-argument-to-parameter-name-because-it-is-an-empty-string/7583/10 "2024-05-16T20:39:49Z")

</div>

Closed on May 16, 2024, 8:39pm UTC


