Wednesday, March 4, 2009

Granting Permissions on Mailboxes using Power shell

If you have some accounts which needs to have full access permission on lots of mailboxes then following power shell command is for you. In order to use this command you have to perform below steps;

1. Create one csv file name it users.csv and save it to C:\ drive.

2. Type text name in first line. Please make sure that there is no space or any other special character after text name otherwise the command will not run.

3. Copy all user ids on which you want to add permissions after text name in same column.

4. Open Exchange Management Shell and type following command and press enter;

Import-CSV "C:\users.csv" | ForEach{Add-MailboxPermission –ID $_.name –AccessRights FullAccess –User [Account id]}

Replace [Account id] with the account id which you want to grant full access permissions on mailboxes.

for verifying that the permissions has been granted, Run following command;

Import-CSV "C:\users.csv" | ForEach{Get-MailboxPermission –ID $_.name –User [Account id}

You can add more columns in you text file if you want by using comma ‘,’ and can reference it in the command as same as you are referencing the first column.

If you don’t have aliases or Ids and have only display names and these display names are in last name first name format such as smith, john then you have to add your names in your .csv file like this “smith, john”

if you want to do opposite and wants to add full access permission for lots users on one mailbox then following will be your command

Import-Csv c:\users.csv | foreach {Add-MailboxPermission –Identity [Account Id] -User $_.users -Accessright Fullaccess -InheritanceType all}

Replace [Account Id] with the mailbox alias or name.