# Batch import of users into Microsoft exchange

**URL:** <https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621>\
**Category:** PowerShell Help\
**Created:** [September 24, 2021, 10:28am UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621 "2021-09-24T10:28:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![csanders](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@csanders](https://forums.powershell.org/u/csanders)\
**Post date:** [September 24, 2021, 10:28am UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/1 "2021-09-24T10:28:37Z")

</div>

I have been running this script and can’t seem to figure out what is going wrong if any one has any advice?

$access = “FullAccess”  
$mailbox = Get-Mailbox -Identity “School House Private Office booking”  
$identity = $mailbox.UserPrincipalName  
$permissions = Get-MailboxPermission -identity $identity

$users = Import-Csv -Path “C:\import\test.csv” -Delimiter “`n”  
foreach($user in $users){  
try{  
$setPermissions = Add-MailboxPermission -Identity $identity -User $user -AccessRights $access  
Write-Host “Successfully added permissions for $user” -ForegroundColor Green  
}catch{  
Write-Host “Failed to add permissions for $user” -ForegroundColor Red  
}  
}

A positional parameter cannot be found that accepts argument ‘House’.  
+ CategoryInfo : InvalidArgument: (🙂 [Get-Mailbox], ParameterBindingException  
+ FullyQualifiedErrorId : PositionalParameterNotFound,Get-Mailbox  
+ PSComputerName : Outlook

Cannot bind argument to parameter ‘Identity’ because it is null.  
+ CategoryInfo : InvalidData: (🙂 [Get-MailboxPermission], ParameterBindingValidationException  
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxPermission  
+ PSComputerName : Outlook

Cannot bind argument to parameter ‘Identity’ because it is null.  
+ CategoryInfo : InvalidData: (🙂 [Add-MailboxPermission], ParameterBindingValidationException  
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-MailboxPermission  
+ PSComputerName : outlook

Successfully added permissions for @{name=agg}  
Cannot bind argument to parameter ‘Identity’ because it is null.  
+ CategoryInfo : InvalidData: (🙂 [Add-MailboxPermission], ParameterBindingValidationException  
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-MailboxPermission  
+ PSComputerName : [outlook.office365.com](http://outlook.office365.com)

Successfully added permissions for @{name=hidden}`Preformatted text`

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 24, 2021, 10:44am UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/2 "2021-09-24T10:44:34Z")

</div>

Connor,  
Welcome to the forum. 👋🏽

Your second line of code already errors out. The rest of the errors depend on the first one. And you do not show the original code …

```auto
$mailbox = Get-Mailbox -Identity Hidden

```

… vs …

```auto
A positional parameter cannot be found that accepts argument ‘House’.

```

You have to specify a unique identifier of the mailbox you want to get.

And please … when you post code or error messages format it as code using the _preformatted text_ button ( **\</\>** ). Simply place the cursor on an empty line, click the button and paste your ocde.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![csanders](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@csanders](https://forums.powershell.org/u/csanders)\
**Post date:** [September 24, 2021, 11:00am UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/3 "2021-09-24T11:00:23Z")

</div>

Hi there,

I have updated all of the code. I am now getting an error after updating the second line to have quotations “MailBoxName” see error below, Any advice with regards to this?

```auto
Cannot process argument transformation on parameter 'User'. Cannot convert value "@{name=aejenkins}" to type 
"Microsoft.Exchange.Configuration.Tasks.SecurityPrincipalIdParameter". Error: "Cannot convert the "@{name=aejenkins}" value of type 
"Deserialized.System.Management.Automation.PSCustomObject" to type "Microsoft.Exchange.Configuration.Tasks.SecurityPrincipalIdParameter"."
    + CategoryInfo : InvalidData: (:) [Add-MailboxPermission], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-MailboxPermission
    + PSComputerName : outlook.office365.com

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 24, 2021, 11:34am UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/4 "2021-09-24T11:34:34Z")

</div>

You may change this …

```auto
$setPermissions = Add-MailboxPermission -Identity $identity -User $user -AccessRights $access

```

… to this …

```auto
$setPermissions = Add-MailboxPermission -Identity $identity -User $($user.Name) -AccessRights $access

```

And BTW: Your Import-Csv command looks weird. Do you really use line breaks as delimiter?

---

<div class="post-metadata">

**Author:** ![csanders](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@csanders](https://forums.powershell.org/u/csanders)\
**Post date:** [September 24, 2021, 12:17pm UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/5 "2021-09-24T12:17:05Z")

</div>

Yeah I do have to use the line breaks, Updated that part of the script that you advised and it worked. Thanks loads for the help!!

---

<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:21pm UTC](https://forums.powershell.org/t/batch-import-of-users-into-microsoft-exchange/17621/6 "2024-05-16T20:21:16Z")

</div>


