Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Created February 7, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royashbrook/9f0d008f07a5e7d05c56c1dfe074b1d5 to your computer and use it in GitHub Desktop.
Save royashbrook/9f0d008f07a5e7d05c56c1dfe074b1d5 to your computer and use it in GitHub Desktop.
# Add/Remove Email Access For Another Mailbox:
# First get a session to work in, unless you have the tools installed
$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri http://mailserver/PowerShell/ `
-Authentication Kerberos
Import-PSSession $Session
# setup users
$a = 'user@email.com' #who's mailbox is it?
$b = 'admin@email.com' #who are we giving access to?
#Add
$p0 = Get-MailboxPermission $a # permissions before
Add-MailboxPermission $a -User $b -AccessRights FullAccess -InheritanceType All
$p1 = Get-MailboxPermission $a # permissions after
"Before:"
$p0
"After:"
$p1
#Remove
$p2 = Get-MailboxPermission $a # permissions before
Remove-MailboxPermission $a -User $b -AccessRights FullAccess -InheritanceType All -Confirm:$false
$p3 = Get-MailboxPermission $a # permissions after
"Before:"
$p2
"After:"
$p3
# Search for an email address on some kind of object:
Get-Recipient -Filter {EmailAddresses -like "*partialemail*"}
#Get Distribution Group Members:
#assumes the following query returns a dg object
$dg = (Get-Recipient -Filter {EmailAddresses -like "*partialemail*"})
Get-DistributionGroupMember -Identity $dg.Name
# Add Email Address to DG or User:
Set-Mailbox "User One" -EmailAddresses @{add="user.one@email.com"}
Set-DistributionGroup "dg name" -emailaddresses @{Add='test@email.com','test1@email.com','test2@email.com'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment