Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1692
  • Last Modified:

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

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
TheGeezer2010
Asked:
TheGeezer2010
  • 5
  • 4
1 Solution
 
endital1097Commented:
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
 
endital1097Commented:
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
 
TheGeezer2010Author Commented:
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
endital1097Commented:
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
 
TheGeezer2010Author Commented:
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
 
endital1097Commented:
you were using $_.users but your column is name so it should be $_.name
that would explain the null
0
 
TheGeezer2010Author Commented:
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
 
endital1097Commented:
np, you'll be a powershell wizard before you know it
0
 
TheGeezer2010Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now