Solved

How to use PS Import-csv to invoke add-mailboxpermission/add-ad-permission for multiple users

Posted on 2010-09-10
9
1,413 Views
Last Modified: 2012-05-10
I am trying to create a command using an import-csv to do the above. I have specified the full path for -identity 'cn=,ou=,dc=,dc=' and using the following link, but it does not seem to work. It seems to run OK, but the permissions are not added. Fairly new to this stuff so go easy please :-)

http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/A_2874-Granting-Permissions-on-Mailboxes-using-Power-shell.html

From this link :-
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/A_2874-Granting-Permissions-on-Mailboxes-using-Power-shell.html

The error I get is :-
Add-MailboxPermission : Cannot bind argument to parameter 'User' because it is
null.
At line:1 char:119
+ Import-Csv c:\scripts\users.csv | foreach {Add-MailboxPermission -Identity 'c
n=,ou=,dc=,dc=' -User  <<<< $_.users -Accessright Fullacces
s -InheritanceType all}
Add-MailboxPermission : Cannot bind argument to parameter 'User' because it is
null.
At line:1 char:119
+ Import-Csv c:\scripts\users.csv | foreach {Add-MailboxPermission -Identity 'c
n=,ou=,dc=,dc=' -User  <<<< $_.users -Accessright Fullacces
s -InheritanceType all}
(NOTE - I have removed the entries for obvious reasons for the object itself).
This looks like it reads the csv file and does not find anything in it ?
I have tried creating the csv file on the server itself using notepad :-
name
name1
name2

save as users.csv

also tried on server

namename1name2

save as csv

also tried creating csv on own machine through excel

name
name1
name2

save as csv - copy over to server

I can get the command to run using individual names without the import-csv, so the naming contexts seem right. Would really appreciate help on this.

Thanks
0
Comment
Question by:TheGeezer2010
  • 5
  • 4
9 Comments
 
LVL 32

Expert Comment

by:endital1097
ID: 33645469
depends on what your column names are but it should be something like the following where the column header is user for the person getting access
Import-Csv c:\scripts\users.csv | foreach-object  { Add-MailboxPermission owner -User $_.user -AccessRights FullAccess }
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33645479
if you could give a sampling of what the csv looks like it would be easier
just the header row, then some made up content for the next row
0
 
LVL 11

Author Comment

by:TheGeezer2010
ID: 33645516
Hi There

It is literally as per the article I gave you in the URL :-

Name
Name1
Name2

The header contains a single column "Name" (row 1), in the same column, underneath are the "Name1" (row 2), "Name2" (row 3).

I hope that explains clearly enough how it is created. If you open this file in Notepad, you see exactly this :-

Name
Name1
Name2

Thanks for the quick response !
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33645541
nothing against the article but it is a little confusing

if you are trying to grant several users access to one mailbox use the following:
Import-Csv c:\scripts\users.csv | foreach-object  { Add-MailboxPermission owner -User $_.Name -AccessRights FullAccess }

if you are trying to grant one user access to several mailboxes use:
Import-Csv c:\scripts\users.csv | foreach-object  { Add-MailboxPermission $_.Name -User delegate -AccessRights FullAccess }
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 11

Author Comment

by:TheGeezer2010
ID: 33645847
Hi There

As you can see from my original mail, I have used this command, but get the error shown. I am not doing anything out of the ordinary here, but it looks like the csv file is being read, but not finding anything in it ? Like I say, I have tried to create the csv file in different ways, but none seems to work.
0
 
LVL 32

Accepted Solution

by:
endital1097 earned 125 total points
ID: 33645862
you were using $_.users but your column is name so it should be $_.name
that would explain the null
0
 
LVL 11

Author Comment

by:TheGeezer2010
ID: 33646075
Hi Endital1097

Firstly thanks for your patience in answering my request - as i said, I am new so did not really know how to put the question but looks like it wasn't too bad :-(

You were spot on with your solution and i am happy that i have subscribed to this site !!!

The points are yours !!
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33646089
np, you'll be a powershell wizard before you know it
0
 
LVL 11

Author Closing Comment

by:TheGeezer2010
ID: 33646096
Patient expert - I am new both to Powershell and to Experts Exchange so was a little apprehensive.

Not sure who reads this but looking for good websites about using Powershell !!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
To show how to create a transport rule 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 >> Rules tab.:  To cr…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

867 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

16 Experts available now in Live!

Get 1:1 Help Now