Solved

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

Posted on 2010-09-10
9
1,393 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
Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

 
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

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
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…
In this video we show how to create an email address policy 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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now