Solved

Exchange Powershell - grant full mailbox access and Send As - import csv?

Posted on 2012-04-10
6
4,774 Views
Last Modified: 2012-04-18
I can't find this one powershell script I found online a while ago, so was checking here to see if anyone has a script similar to what I'm looking for;

I want to be able to grant full mailbox permissions for a few different users to the same few mailboxes.

So for example, I have mailbox 1, mailbox 2, mailbox 3, mailbox 4.
What I'm trying to do is grant John, Bob, Sally, Rick and Jason all full mailbox access and SendAs access to those mailboxes (1 -4).

Would this have to be done by having a 2 column CSV file and what would the script/commands be?

These are the 2 commands I have from another script;

Add-MailboxPermission $mailbox -User $employee -AccessRights:FullAccess -confirm: $false
Add-ADPermission -Identity $mailbox -User $employee -AccessRights ExtendedRight -ExtendedRights "send as"

Open in new window

0
Comment
Question by:garryshape
  • 4
  • 2
6 Comments
 

Author Comment

by:garryshape
Comment Utility
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
having csv like:

user, mailbox
john,<johnmailbox>
bob, <bobmailbox>

make sure to have the headers in the csv file (user, mailbox)

the following script will do what u want:
Import-Csv c:\scripts\test.txt | foreach {
Add-MailboxPermission $_.mailbox -User $_.user -AccessRights:FullAccess -confirm: $false
Add-ADPermission -Identity $_.mailbox -User $_.user -AccessRights ExtendedRight -ExtendedRights "send as"
}

Open in new window

0
 

Author Comment

by:garryshape
Comment Utility
Thanks sedgwick, yes that seems to work. Now all I have to do is add usernames instead of manually typing each command.

One other question to complement this code, do you know how I could then add the command to remove the mailbox automapping in this script for the users who were just granted the access?

Something like this?

$Thelist = Import-csv “C:\thelist.csv”
ForEach($theobject in $thelist) {$theMBDN = (Get-Mailbox $theobject.themailbox).distinguishedname;
Add-ADPermission $thembDN -Extendedrights “Send As” -User $theobject.theuser;
Add-MailboxPermission $thembDN -Accessrights “FullAccess” -User $theobject.theuser
}

# Remove the auto-mapping of the new granted mailboxes

$DomainController = $Mailbox.OriginatingServer
$LDAPUser=[ADSI]"LDAP://$($DomainController)/$($TheUser)"
$LDAPUser.msExchDelegateListLink.Remove(((Get-Mailbox $TheMailbox)))
$LDAPUser.SetInfo()

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:garryshape
Comment Utility
or will the -AutoMapping:$false work for the Add-MailboxPermission command?
0
 

Author Comment

by:garryshape
Comment Utility
I'm sorry, I mean this. Would this work?

$Thelist = Import-csv “H:\MailboxAccess.csv”
ForEach($theobject in $thelist) {$theMBDN = (Get-Mailbox $theobject.themailbox).distinguishedname;
Add-ADPermission $thembDN -Extendedrights “Send As” -User $theobject.theuser;
Add-MailboxPermission $thembDN -Accessrights “FullAccess” -User $theobject.theuser 
}

# Remove the auto-mapping of the mailbox from the user's account
$DomainController = $TheMailbox.OriginatingServer
$LDAPUser=[ADSI]"LDAP://$($DomainController)/$($TheMailbox.DistinguishedName)"
$LDAPUser.msExchDelegateListLink.Remove(((Get-Mailbox $TheUser).DistinguishedName))
$LDAPUser.SetInfo()

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
i think u missed something cause my code reads list of users, u don't have to run the script for each one separately.

read my post again, i described how the csv should look like with the headers and stuff.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell code used to work 7 40
exchange, outlook 6 28
Installing Git and chefdk via bat script 8 16
Circular Logging 2 23
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
A procedure for exporting installed hotfix details of remote computers using powershell
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

11 Experts available now in Live!

Get 1:1 Help Now