ExchangePowershell

From Piszczynski
Revision as of 08:11, 27 May 2020 by piszczynski>Aleks (→‎Handy Commands for Exchange Powershell)

Connect to O365 Exchange

  • $UserCredential = Get-Credential
    • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
      • Import-PSSession $Session -DisableNameChecking

Then to close the session

  • Remove-PSSession $Session


Hide O365 group from GAL ( as this cannot be done on admin portal )

  • Set-UnifiedGroup <group> -HiddenFromAddressListsEnabled $true


Handy Commands for Exchange Powershell

  • Add permission to calendar:
    • This will give a user permissions to another calendar
      • Set-MailboxFolderPermission “CalendarName:\calendar” –User default –AccessRights reviewer
  • Send on Behalf
    • This will grant Charles permissions to send on behalf of Gert.
      • Set-Mailbox gert.mailbox -GrantSendOnBehalfTo charles.surname
  • Send As
    • This will grant Charles permissions to send as Gert.
      • Add-ADPermission gert.mailbox -ExtendedRights Send-As -user charles.surname
  • Full Mailbox Access
    • This will grant Charles full access to Gert's mailbox.
      • Add-MailboxPermission -Identity gert.mailbox -User charles.surname


Add full access permission to all mailboxes to an account:

  • Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (Alias -ne 'Admin')} | Add-MailboxPermission -User UserAccount@domain.com -AccessRights fullaccess -InheritanceType all -AutoMapping:$False

Add Send as permissions to mailboxes:

  • $UserMailboxes = Get-Mailbox | Where {$_.RecipientTypeDetails -eq “<Type of mailbox>”}
    • $UserMailboxes | Add-RecipientPermission -AccessRights SendAs –Trustee <identity>

Get all disconnected mailboxes:

  • $dbs = Get-MailboxDatabase; $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq "Disabled"} | Format-Table DisplayName,Database,DisconnectDate

Exchange issues Powershell

Check the Database availability groups cmdlet - use to find out if exchange server is the Primary or Secondary

  • Get-DatabaseAvailabilityGroup

You can get all the details you need by using the following command:

  • Get-DatabaseAvailabilityGroup | fl
  • Get-DatabaseAvailabilityGroup -status

Sometimes the witness will fail, you can check the status of the witness by using the cluster resource cmdlet:

  • ipmo failoverclusters
  • Get-ClusterResource

This will tell you where the witness stores the file. If the DAG finds the resource unrelibale it might mark it as failed - you can restart this by using start-cluster resource:

  • Get-ClusterResource | Start-ClusterResource

Get the log for the cluster

  • Get-ClusterLog -Destination <File pathway>