Today, I share with you my code to build a function to add or remove Full Mailbox Access with PowerShell. Feel free to use and modify my code. If you made some improvements, please share it.
1: <#
2: .Synopsis
3: Connect a remote session to the Exchange 2010 server.
4: Add or remove Full Access permission for an account (user)
5: .DESCRIPTION
6: This cmdlet need to have access to the cmdlet of Exchange.
7: Its script to be used with Exchange 2010.
8: Version 1.0
9: Script by Jeremie Lauzier - Network Administrator, 2015-06-03
10: .EXAMPLE
11: Add Full Access permission for Felicity Jones on the account Ray Plamer.
12: Set-XXXFullMailboxAccess -accountmodify palmerr -accountFMA jonesf -choice Add
13: .EXAMPLE
14: Remove Full Access permission for Felicity Jones on the account Ray Plamer.
15: Set-XXXFullMailboxAccess -accountmodify palmerr -accountFMA jonesf -choice Remove
16: .EXAMPLE
17: All parameters are mandatory. So just type Set-XXXFullMailboxAccess and field choice one at a time.
18: #>
19: function Set-XXXFullMailboxAccess
20: {
21: [CmdletBinding()]
22: [OutputType([int])]
23: Param
24: (
25: # Define the account to modify
26: [Parameter(Mandatory=$true,
27: ValueFromPipelineByPropertyName=$true,
28: Position=0)]
29: $accountmodify,
30: # Define the account who will have Full Access or Remove it.
31: [Parameter(Mandatory=$true)]
32: $accountFMA,
33: # Add or remove Full Access
34: [Parameter(Mandatory=$true)]
35: [ValidateSet("Add", "Remove")]
36: $choice
37: )
38: Begin
39: {
40: $exchsession=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourservername/powershell
41: Import-PSSession $exchsession -AllowClobber
42: }
43: Process
44: {if ($choice -eq "Add")
45: {
46: Add-MailboxPermission -Identity $accountmodify -User $accountFMA -AccessRights 'FullAccess'
47: }
48: if ($choice -eq "Remove")
49: {
50: Remove-MailboxPermission -Identity $accountmodify -User $accountFMA -InheritanceType 'All' -AccessRights 'FullAccess' -Confirm:$false
51: }
52: Get-MailboxPermission -Identity $accountmodify | where {$_.AccessRights -eq "FullAccess"} | Format-Table User, AccessRights -AutoSize
53: }
54: End
55: {
56: Remove-PSSession $exchsession
57: }
58: }
No comments:
Post a Comment