Powershell

Table of Contents

3.2 Exchange

Installing Exchange - Module (On-prem -Cloud)

For Online Exchange management add the below permissions to admin account
Set-executionpolicy –executionpolicy unrestricted
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic –AllowRedirection
Import-PSSession $exchangeSession



Mailbox permission check and add

get-mailboxpermission -Identity "jdoe@poshpython.com"
add-mailboxpermission -Identity "jdoe@poshpython.com" -User "wendywu@poshpython.com" -AccessRights FullAccess
Add-MailboxPermission -Identity "jdoe@poshpython.com" -User "wendywu@poshpython.com" -AccessRights FullAccess -AutoMapping:$false



Send permissions

Set-Mailbox -Identity "jdoe@poshpython.com" -GrantSendOnBehalfTo "wendywu@poshpython.com"
Add-RecipientPermission -Identity "jdoe@poshpython.com" -AccessRights sendas -Trustee "wendywu@poshpython.com"



Set mailbox type

Set-Mailbox MarketingDept1 -Type Shared
Set-Mailbox -Type:
Set-Mailbox MarketingDept1 -Type Shared -automapping:$false



Mailbox Permissions

Get-Mailbox | Get-MailboxPermission -User "wendywu@poshpython.com"



Calendar Permission

add-MailboxFolderPermission -Identity "wendywu@poshpython.com":\calendar -User "jdoe@poshpython.com" -AccessRights editor


If above is already added and you wish to modify calendar permission

set-MailboxFolderPermission -Identity "wendywu@poshpython.com":\calendar -User "jdoe@poshpython.com" -AccessRights editor



To see current permissions

get-MailboxFolderPermission -Identity "wendywu@poshpython.com":\calendar



Forwarding mail

Set-Mailbox -Identity "wendywu@poshpython.com" -ForwardingSMTPAddress "jdoe@poshpython.com"



Add 1 user to all room calendars

$mailbox = Get-Mailbox -ResultSize unlimited -RecipientTypeDetails roommailbox
ForEach ($calendar in $mailbox) {
Add-MailboxFolderPermission -Identity "$($calendar.alias):\Calendar" -User "jdoe@poshpython.com" -AccessRights editor
}



Get Mailbox total size in GB

Get-Mailbox "wendywu@poshpython.com" | Get-MailboxStatistics | Add-Member -MemberType ScriptProperty -Name TotalItemSizeinMB -Value {$this.totalitemsize.value.ToMB()} -PassThru | Format-Table DisplayName,TotalItem*



Exchange Mail Trace Rule ID find

get-transportrule | select -Property * | select name, guid



Hide disabled user from address list

Get-ADUser mervw | Set-ADUser -Replace @{msExchHideFromAddressLists="TRUE"}



Get all Room calendars

Get-MailBox | where {$_.ResourceType -eq "Room"} | select name | ft -autosize



Set Room calendar booking days

Set-CalendarProcessing roomname-BookingWindowsInDays 365



Get all Room permissions

$ConPermission = @()
$rooms = get-mailbox -RecipientTypeDetails roommailbox -resultsize unlimited
Foreach ($Mailbox in $rooms)
{
$perm = Get-mailboxfolderpermission -identity ($Mailbox.alias+':\calendar')
$userN = $null
$userC = $null
$userA = $null
$userPA = $null
$userNEA = $null
$userR = $null
$userE = $null
$userPE = $null
$userO = $null
$userAO = $null
$userL = $null
foreach ($acc in $perm){
$user = $null
$user = $acc.user
$user = $user.ToString()
$access = $acc.accessrights
Switch($access){
None { $userN += $user + ","}
Contributor { $userC += $user + ","}
author { $userA += $user + ","}
PublishingAuthor { $userPA += $user + ","}
NonEditingAuthor { $userNEA += $user + ","}
Reviewer { $userR += $user + ","}
Editor { $userE += $user + ","}
PublishingEditor { $userPE += $user + ","}
Owner { $userO += $user + ","}
Availabilityonly { $userAO += $user + ","}
Limiteddetails { $userL += $user + ","}
default {"Something else happened"}
}
}
$roomp = "" | select ConfRoomname,None,Contributor,author,PublishingAuthor,NonEditingAuthor,Reviewer,Editor,PublishingEditor,Owner, Availabilityonly,Limiteddetails
$roomp.ConfRoomname = $Mailbox.displayname
$roomp.None = $userN
$roomp.Contributor = $userC
$roomp.author = $userA
$roomp.PublishingAuthor = $userPA
$roomp.NonEditingAuthor = $userNEA
$roomp.Reviewer = $userR
$roomp.Editor = $userE
$roomp.PublishingEditor = $userPE
$roomp.Owner = $userO
$roomp.Availabilityonly = $userAO
$roomp.Limiteddetails = $userL
$ConPermission += $roomp
}
$ConPermission | export-csv .\ConfPermissions.csv -notypeinformation


Visit next page to learn about - 3.3 365