Office 365 Example Code

The basics getting started with Office 365 PowerShell

Get-MailboxFolderPermission, Get-MailboxCalenderFolder (PublishDateRange, DetailLevel), Get-Mailbox -ResultSize unlimited, Get-Mailbox | FT Alias,Displayname,EmailAddresses, Get-Mailbox |FT Alias,Displayname,EmailAddresses –Wrap, Get-Mailbox | Group RecipientTypeDetails, Get-Mailbox |Sort-Object Alias, Get-Mailbox |Sort Alias Descending, Get-Mailbox |FT -AutoSize, Get-Mailbox |Sort RecipientTypeDetails |FT Name,Alias
-Groupby RecipientTypeDetails

 

Get-Mailbox | Where {$_.Property -“Value”}, Get-Mailbox | Where {$_.Property -“Value”} | Select Property1,Property2, Get-Mailbox | Where {$_.RecipientTypeDetails -eq “UserMailbox”}, Get-User | Where {$_.Department -eq “Sales”}, Get-User | Where {($_.Department -eq “Sales”) -or ($_.Department -eq “Marketing”)}, Get-User | Where {($_.Department -eq “Sales”) -and ($_.Title -eq “Manger”)}, Get-User | Where {($_.Department -eq “Sales”) -or ($_.Department -eq “Marketing”) -and ($_.Title -eq “Manger”)}, Get-User | Where {$_.Department -like “Sales*”}, Get-User | Where {$_.StateOrProvince -ne “USA”}

.

$UserCredential = Credential user@someplace.com
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Remove-PSSession $Session

.
How to Query the different Mailbox’s for specific results.

$user = "Krishna.k" get-mailbox -identity $user | Get-MailboxPermission | ?{($_.IsInherited -eq $False) -and -not ($_.User -match "NT AUTHORITY")}

.
.
.
.
• Querying Clutter, on a Single User, Bulk/Multiple, Stored Mail

Enable clutter for a specific mailbox

Get-Mailbox "John" | Set-Clutter -Enable $True

Enable Clutter for of the mailboxes that don’t use Clutter

Get-Mailbox | ?{-not (Get-Clutter -Identity $_.Alias).IsEnabled} | %{Set-Clutter -Identity $_.Alias -Enable $false}

Enable clutter for ALL user’s mailboxes (Bulk mode)

Get-Mailbox -ResultSize Unlimited | Set-Clutter -Enable $True

Display information about Clutter folder – number of items and size

Get-Mailbox –ResultSize Unlimited –RecipientTypeDetails UserMailbox | % {Get-MailboxFolderStatistics –Identity $_.Alias } | Where-Object {$_.Name –Like "Clutter" } | FT Identity, ItemsInFolder, FolderSize –AutoSize

Create a transport rule to bypass the Clutter folder
New-TransportRule -Name <name_of_the_rule> -SubjectContainsWords “Meeting” -SetHeaderName “X-MS-Exchange-Organization-BypassClutter” -SetHeaderValue “true”

New-TransportRule -Name "dont clutter o365 Meetings" -SubjectContainsWords "o365 Meeting" -SetHeaderName "X-MS-Exchange-Organization-BypassClutter" -SetHeaderValue "True"

Create a folder tag to delete items from the Clutter folder after X days (You will need to add the “clutter tag” to the required retention policy)
New-RetentionPolicyTag –Name “<Tag name>” –AgeLimitForRetention <Number of days> –Comment “<Comment>” –RetentionEnabled $True –RetentionAction <action type> –Type Clutter

New-RetentionPolicyTag –Name "Delete mail items from Clutter folder after 60 days" –AgeLimitForRetention 60 –Comment "Retention tag to Delete mail items from Clutter folder after 60 days" –RetentionEnabled $True –RetentionAction DeleteAndAllowRecovery –Type Clutter

Disable Clutter for a specific mailbox

Get-Mailbox John | Set-Clutter -Enable $False

Disable Clutter for of the mailboxes that use Clutter

Get-Mailbox | ?{-not (Get-Clutter -Identity $_.Alias).IsEnabled} | %{Set-Clutter -Identity $_.Alias -Enable $false}

Disable clutter for all users’ mailboxes (Bulk mode)

Get-Mailbox -ResultSize Unlimited | Set-Clutter -Enable $False

 

• Export and display information about Email addresses

Display E-mail address information

Get-Mailbox Billy | Select DisplayName,EmailAddresses

Display information about Primary E-mail address

Get-Mailbox Billy | Select-Object DisplayName,PrimarySmtpAddress
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress

Expend the “E-mail address property”

Get-Mailbox Angelina | Select-Object -ExpandProperty EmailAddresses
  • –NoTypeInformation– this option prevents from PowerShell to add unnecessary information to the CSV file.
  • -Encoding UTF8 – in case that the objects such as users, or mailboxes include non-English characters, we can add this “format parameter” to enable PowerShell export information that includes non-English characters.

Example of PowerShell syntax for exporting information to various file types

Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses |  Out-File "C:\Temp\Exchange Online recipients.TXT"
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses |  Export-CSV "C:\Temp\Exchange Online recipients.CSV" –NoTypeInformation -Encoding UTF8
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses |  ConvertTo-Html | Out-File "C:\Temp\Exchange Online recipients.HTML"
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses |  Export-Clixml  "C:\Temp\Exchange Online recipients.XML"

Optimise the displayed results – recipient E-mail addresses using Hash table

Get-Mailbox Christina | Select-Object DisplayName,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object { $_ -cmatch “smtp:*”} | ForEach-Object {$_ -replace 'smtp:'  }) -join ';' } }
DisplayName EmailAddresses
----------- --------------
Christina Aguilera Christina-Alias02@o365info.com;Christina@o365pilot.com

Display only Primary E-mail address

Get-Mailbox Billy | Select Alias,PrimarySmtpAddress
Get-Mailbox Billy | Select-Object DisplayName,@{Name=”Primary Email Address”;Expression={ $_.EmailAddresses | Where-Object {$_ -cmatch “SMTP:*”}}}

Display only SIP address

Get-Mailbox | Select-Object DisplayName,@{Name=”SIP Email Address ”;Expression={$_.EmailAddresses |Where-Object {$_ -LIKE “sip:*”}}}

Display only x500 E- address

Get-Mailbox | Select-Object DisplayName,@{Name="x500 Email Address";Expression={$_.EmailAddresses |Where-Object {$_ -cmatch "x500:*"}}}
  • Get-Recipient
  • Get-Mailbox -SoftDeletedMailbox
  • Get-UnifiedGroup

Performing a search of E-mail address, with a specific domain name suffix

Searching “Hidden” Email addresses

Removing (deleting) E-mail address

Set-Mailbox Christina -EmailAddresses @{remove="Christina-Alias02@o365info.com"}
Set-Mailbox Christina -EmailAddresses @{"-"="Christina-Alias01@o365info.com" }

Remove all E-mail addresses that have a specific domain name (Bulk mode)

$RemoveDomain = Read-Host "Type the domain name suffix that you look for"
$AllMailboxes = $AllMailboxes = Get-mailbox | Where {$_.emailaddresses -like "smtp:*@$RemoveDomain"}
ForEach ($Mailbox in $AllMailboxes){
write-host -ForegroundColor green "Removing the Alias That include the domain name $RemoveDomain :" $Mailbox.EmailAddresses "for" $Mailbox.DisplayName
Set-Mailbox $Mailbox.DisplayName -EmailAddresses @{Remove=$Mailbox.EmailAddresses} -WhatIf }

Remove the smtp prefix: Using the Replace parameter

Get-Mailbox Christina | Select-Object DisplayName,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object {$_ -cmatch "smtp:*"} | ForEach-Object {$_ -replace 'smtp:' }) }}

Count the number of Proxy E-mail addresses

@{Name="Number of Proxy Email";Expression={($_.EmailAddresses | Where-Object {$_ -cmatch "smtp:*"}).count}}

The “complete” PowerShell command syntax

Get-Mailbox | Select-Object DisplayName,@{Name="Primary Email Addresses";Expression={$_.EmailAddresses | Where-Object {$_ -cmatch "SMTP:*"}}} ,@{Name="Proxy Email Addresseses";Expression={$_.EmailAddresses | Where-Object {$_ -cmatch "smtp:*"}}} , @{Name="Number of Proxy Email";Expression={($_.EmailAddresses | Where-Object {$_ -cmatch "smtp:*"}).count}} ,@{Name="SIP Email Addresseses";Expression={$_.EmailAddresses |Where-Object {$_ -LIKE "sip:*"}}} ,@{Name="X500 EmailAddresseses";Expression={$_.EmailAddresses | Where-Object {$_ -LIKE "x500:*"}}}
DisplayName : Alice Good
Primary Email Addresses : SMTP:Ayelet@o365info.com
Proxy Email Addresseses : smtp:Ayelet@o365info2.onmicrosoft.com
Number of Proxy Email : 1
SIP Email Addresseses : SIP:Ayelet@o365info.com
X500 EmailAddresseses :
 
DisplayName : Angelina Jolie
Primary Email Addresses : SMTP:Angelina-NEW01@o365info.com
Proxy Email Addresseses : {smtp:Angelina@o365pilot.com, smtp:kk@o365info.com, smtp:Angelina@o365info.com, smtp:Angelina-Alias03@o365info.com...}
Number of Proxy Email : 5
SIP Email Addresseses :
X500 EmailAddresseses :

View the different type of Exchange Online recipients, when using the Get-Recipient

Get-Recipient | Group RecipientTypeDetails | Select name, count
Name                           Count
----                           -----
MailUniversalDistributionGroup    23
UserMailbox                       54
MailContact                       14
MailUniversalSecurityGroup        14
DiscoveryMailbox                   1
SharedMailbox                     13
DynamicDistributionGroup           5
MailUser                          13
EquipmentMailbox                   1
PublicFolder                       5
RoomMailbox                        7
RoomList                           1

Exchange Online mailboxes by “type”

Get-Mailbox | Where {$_.RecipientTypeDetails -eq "UserMailbox"}
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "RoomMailbox"}
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "SharedMailbox"}
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "EquipmentMailbox"}

Soft Deleted Exchange Online mailboxes

Get-Mailbox -SoftDeletedMailbox
Get-Mailbox -InactiveMailboxOnly

View the different type of Exchange Online recipients, when using the Get-Mailbox

Get-Mailbox | Group RecipientTypeDetails | Select name,count
Name             Count
----             -----
UserMailbox         54
DiscoveryMailbox     1
SharedMailbox       13
EquipmentMailbox     1
RoomMailbox          7

View the different type of Exchange Online recipients, when using the Get-User

Get-User | Group RecipientTypeDetails | Select name,count
Name             Count
----             -----
User                13
UserMailbox         54
DiscoveryMailbox     1
SharedMailbox       13
MailUser            13
EquipmentMailbox     1
RoomMailbox          7

The Exchange Online PowerShell cmdlets – Get-Contact versus Get-MailContact

Get-MailContact | Group RecipientTypeDetails | Select name, count
Name        Count
----        -----
MailContact    14
Get-Contact | Group RecipientTypeDetails | Select name, count
Name        Count
----        -----
MailContact    14

Public Folder recipient – Mail enables Public Folder

Get-MailPublicFolder, Get-DistributionGroup + Filter, Get-Group | Where {$_.GroupType -like “*security*”}, Get-DynamicDistributionGroup, Get-UnifiedGroup

Exchange Online recipients classification

Get-mailbox Shared-MB01 | select Name, RecipientType,RecipientTypeDetails
Name        RecipientType RecipientTypeDetails
----        ------------- --------------------
Shared-MB01 UserMailbox   SharedMailbox

Office 365 (Azure Active Directory) infrastructure

Get-Msoluser, Get-MsolGroup, Get-MsolContact, Get-MsolUser -ReturnDeletedUsers
Get-MsolUser -UserPrincipalName "bob@o365info.com" | fl DisplayName,ProxyAddresses,SignInName,UserPrincipalName
DisplayName : Bob marley
ProxyAddresses : {smtp:bob2@o365pilot.com, SMTP:bob@o365info.com, smtp:bob@o365info2.onmicrosoft.com}
SignInName : bob@o365info.com
UserPrincipalName : bob@o365info.com

Get information about Exchange on-Premises synchronized/hybrid recipients

Get-Recipient | Where {$_.Capabilities -like "*MasteredOnPremise"} | FL DisplayName,EmailAddresses
Get-Recipient | Where {$_.Capabilities -like "*MasteredOnPremise"}  | Group-Object -Property RecipientTypeDetails |select Count, Name
Count Name
----- ----
21 UserMailbox
2 MailContact
11 MailUser
2 MailUniversalDistributionGroup
3 RoomMailbox
4 SharedMailbox
1 MailUniversalSecurityGroup

Performing a search for E-mail address that includes a specific domain name suffix

Get-Recipient -ResultSize unlimited | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-Mailbox -SoftDeletedMailbox | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-UnifiedGroup | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses

Performing a search for UPN Name and E-mail address that include a specific domain name suffix

Get-Msoluser -all | Where {$_.UserPrincipalName -like "*@o365info.com"} | FL DisplayName,UserPrincipalName
Get-Msoluser -all | Where {$_.ProxyAddresses -like "*@o365info.com"} | FL DisplayName,UserPrincipalName, ProxyAddresses
Get-MsolUser -ReturnDeletedUsers | Where {$_.UserPrincipalName -like "*@o365info.com"} | FL DisplayName,UserPrincipalName

Exchange Online recipient type – Mailbox recipient

Get-Mailbox | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-Contact | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-MailContact | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-MailUser | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-User | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-MailPublicFolder | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-DistributionGroup | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
Get-DynamicDistributionGroup | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses

Count the number of Exchange Online mailboxes

Get-Mailbox -ResultSize Unlimited | Group-Object -Property RecipientTypeDetails
Count Name Group
----- ---- -----
45 UserMailbox {Adele, Alice Good, Alicia Keys...}
1 DiscoveryMailbox {Discovery Search Mailbox}
9 SharedMailbox {DMARC and Spoof E-mail, E-mail attachments Mailbox, Help desk support tickets, Shared-MB01...}
4 RoomMailbox {Room03, room04, Room-MB01, Room-MB02}

Display information about a specific type of Exchange mailboxes

Get-Mailbox | Where {$_.RecipientTypeDetails -eq "UserMailbox"} |FT Alias,RecipientTypeDetails
DisplayName        RecipientTypeDetails
-----------        --------------------
Adele              UserMailbox         
Alicia Keys        UserMailbox         
Angelina Jolie     UserMailbox         
Aretha Franklin    UserMailbox         
Beatles the        UserMailbox         
Beyonce            UserMailbox         
Billy              UserMailbox         
Bob marley         UserMailbox

Filter the search result | Display information only about Exchange Online mailboxes considered as “Room mailbox”, “Shared Mailbox”, “Equipment Mailbox”

Get-Mailbox | Where {$_.RecipientTypeDetails -eq "RoomMailbox"} | FT Alias,RecipientTypeDetails
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "SharedMailbox"} | FT Alias,RecipientTypeDetails
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "EquipmentMailbox"} | FT Alias,RecipientTypeDetails

Display information about a specific type of Exchange recipients

Get-Recipient | Sort RecipientType | Select  DisplayName,RecipientType
DisplayName                RecipientType                 
-----------                -------------                 
test-01                    DynamicDistributionGroup      
test-02                    DynamicDistributionGroup      
Test004                    MailUniversalDistributionGroup
Billy group                MailUniversalDistributionGroup
Marketing                  MailUniversalDistributionGroup
ex2010                     MailUser                      
test002                    PublicFolder                  
test300                    PublicFolder                  
Christina Aguilera         UserMailbox                   
Chris Brown                UserMailbox

Display information about all Exchange Online recipients, contacts, mail users

Get-Contact | FT Name,RecipientType
Get-MailContact | FT Name,RecipientType
Name                       RecipientType
----                       -------------
Allie Bellew               MailContact  
Chris Norred               MailContact  
Cindy White                MailContact
Get-User | Sort RecipientType | Select  DisplayName,RecipientType
 

Display information about all the available Exchange Online group types

Get-Group | Sort GroupType |Select Name,DisplayName,GroupType
Name                                              DisplayName            GroupType                 
----                                              -----------            ---------                 
inbal01                                           inbal01                Universal                 
SharedMailboxes-group                             SharedMailboxes-group  Universal                 
office365_3fdb9f3bff                              office365              Universal                 
Support                                           Support                Universal, SecurityEnabled
info                                              info                   Universal, SecurityEnabled
ATP-users                                         ATP-users              Universal, SecurityEnabled
test03                                            test03                 Universal, SecurityEnabled
Mobile Users                                      Mobile Users           Universal, SecurityEnabled

Display information about all Exchange Online dynamic distribution groups

Get-DynamicDistributionGroup |FT Name,DisplayName,RecipientType
Name    DisplayName RecipientType           
----    ----------- -------------           
sm-dy   sm-dy       DynamicDistributionGroup
test-01 test-01     DynamicDistributionGroup
test-07 test-07     DynamicDistributionGroup

Display information about all Exchange Online groups that considered as – Unified groups

Get-UnifiedGroup | FT Name,DisplayName,RecipientType,AccessType
Name                           DisplayName         RecipientType                  AccessType
----                           -----------         -------------                  ----------
BOB-OFFICE365_5d7917ddd4       BOB-OFFICE365       MailUniversalDistributionGroup Public    
Eyal-001-uni_7eca52b0ac        Eyal-001-uni        MailUniversalDistributionGroup Private   
Eyal-002-uni-PUBLIC_3bf86941dd Eyal-002-uni-PUBLIC MailUniversalDistributionGroup Public    
office365_3fdb9f3bff           office365           MailUniversalDistributionGroup Public

Display information about all Exchange Online groups that considered as a “Security group.”

Get-Group | Where {$_.GroupType -like "*security*"} | FT Name,DisplayName,GroupType
Name                                              DisplayName            GroupType                 
----                                              -----------            ---------                 
Organization Management                                                  Universal, SecurityEnabled
Recipient Management                                                     Universal, SecurityEnabled
View-Only Organization Management                                        Universal, SecurityEnabled
UM Management                                                            Universal, SecurityEnabled

Display information about all Exchange Online Public Folders

Get-MailPublicFolder | FT Alias,DisplayName,RecipientType,EmailAddresses
Alias   DisplayName RecipientType
-----   ----------- -------------
root1   root        PublicFolder 
test002 test002     PublicFolder 
Jobs    Jobs        PublicFolder 
test300 test300     PublicFolder 
test400 test400     PublicFolder

Display information about Exchange Online Public Folders + “child Public Folders”

Get-PublicFolder "\" -Recurse
Name              Parent Path               
----              -----------               
IPM_SUBTREE                                 
Jobs              \                         
Test200           \                         
test300           \                         
test400           \                         
layer-01-Test-400 \test400                  
layer-02-test400  \test400\layer-01-Test-400
test500           \

Display all Exchange Online mailboxes which have an email with a specific domain name suffix.

Get-Mailbox | Where {$_.EmailAddresses -like "*@o365info.com"} | FL DisplayName,EmailAddresses
DisplayName    : Adele
EmailAddresses : {SPO:SPO_d5a46ab4-0922-4d9c-b2f3-3ddbff048a32@SPO_e95bcc9e-2927-483d-ad36-7311a7152bdd, smtp:Adele@o365info.com, SMTP:Adele@o365info2.onmicrosoft.com, SIP:Adele@o365info.com}
DisplayName    : Alicia Keys
EmailAddresses : {SIP:Alicia@o365info.com, smtp:Alicia@o365info2.onmicrosoft.com, SMTP:Alicia@o365info.com}
DisplayName    : Angelina Jolie
EmailAddresses : {SPO:SPO_5b27dc17-68b0-442e-804b-aee5b4df9847@SPO_e95bcc9e-2927-483d-ad36-7311a7152bdd, SIP:Angelina@o365info.com, SMTP:Angelina@o365info.com, smtp:Angelina@o365info2.onmicrosoft.com}
DisplayName    : Aretha Franklin
EmailAddresses : {SIP:Aretha@o365info.com, SMTP:Aretha@o365info.com, smtp:Aretha@o365info2.onmicrosoft.com}

Display all Exchange Online mailboxes which their primary E-mail address includes a specific alias

Get-Mailbox | Where {$_.primarysmtpaddress -like "bob*"} | FL DisplayName,EmailAddresses
DisplayName    : Bob marley
EmailAddresses : {smtp:mrkt1@o365info.com, smtp:Albert@o365info.com, smtp:bobm@o365info.com, SIP:bob@o365info.com...}

Display all Exchange Online mailboxes, which their E-mail address includes a specific Alias

Get-Mailbox | Where {$_.EmailAddresses -like "*bob*"} | FL DisplayName, EmailAddresses
DisplayName    : Bob marley
EmailAddresses : {smtp:mrkt1@o365info.com, smtp:Albert@o365info.com, smtp:bobm@o365info.com, SIP:bob@o365info.com...}

Display information about all Exchange Online mailboxes that consider as – “Soft deleted mailboxes”

Get-Mailbox -SoftDeletedMailbox | FT Name,Alias,IsSoftDeletedByRemove,IsInactiveMailbox
Name                   Alias   IsSoftDeletedByRemove IsInactiveMailbox
----                   -----   --------------------- -----------------
room001                room001                  True             False
Katy Perry             Katy                     True             False
michael jackson        michael                  True             False
James Brown_eb17e65f06 James                    True             False
Test100                Test100                  True              True
test501                test501                  True             False
test500                test500                  True             False

Display Exchange Online which their user account (owner) is disabled

Get-mailbox | Where {$_.AccountDisabled  -eq $True} | FT Alias, UserPrincipalName,AccountDisabled
Alias                                                        UserPrincipalName                                                         AccountDisabled
-----                                                        -----------------                                                         ---------------
Angelina                                                     Angelina@o365info.com                                                                True
DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852}@o365info.com            True
DMARC-Spoof                                                  DMARC-Spoof@o365info.com                                                             True
hd                                                           hd@o365info.com                                                                      True
Shared-MB01                                                  Shared-MB01@o365info.com                                                             True
Shared-MB02                                                  Shared-MB02@o365info.com                                                             True
Shared-MB03                                                  Shared-MB03@o365info.com                                                             True

Display information about all Exchange Online mailboxes that consider as – “Inactive mailboxes “

Get-Mailbox -InactiveMailboxOnly |FT Name,Alias,IsSoftDeletedByRemove,IsInactiveMailbox
Name    Alias   IsSoftDeletedByRemove IsInactiveMailbox
----    -----   --------------------- -----------------
Test100 Test100                  True              True

Display Exchange mailboxes with a specific time zone

Get-Mailbox | Get-MailboxRegionalConfiguration | Where {{$_.TimeZone -like "*Pacific Standard Time*"}
Identity             Language        DateFormat TimeFormat TimeZone                                                                                                                                          
--------             --------        ---------- ---------- --------                                                                                                                                          
Demi                 en-US           M/d/yyyy   h:mm tt    Pacific Standard Time                                                                                                                             
Grace jones          en-US           M/d/yyyy   h:mm tt    Pacific Standard Time                                                                                                                             
Rihanna              en-US           M/d/yyyy   h:mm tt    Pacific Standard Time

Get a list of available Time Zones values

Get-ChildItem "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Time zones" | FL | FL pschildname
PSChildName : Afghanistan Standard Time
PSChildName : Alaskan Standard Time
PSChildName : Aleutian Standard Time
PSChildName : Altai Standard Time
PSChildName : Arab Standard Time
PSChildName : West Pacific Standard Time
PSChildName : Yakutsk Standard Time

Display information about Exchange Online mailboxes with a specific Language.

Get-Mailbox | Get-MailboxRegionalConfiguration | Where {$_.Language -like "*en-GB*"}
Identity             Language        DateFormat TimeFormat TimeZone                                                                                                                                          
--------             --------        ---------- ---------- --------                                                                                                                                          
Angelina             en-GB           dd/MM/yyyy HH:mm      Israel Standard Time                                                                                                                              
Ayelet_9acbcfb3dc    en-GB           dd/MM/yyyy HH:mm      Israel Standard Time                                                                                                                              
George Michael       en-GB           dd/MM/yyyy HH:mm      Israel Standard Time                                                                                                                              
onprem120            en-GB           dd/MM/yyyy HH:mm      Samoa Standard Time

Display information about Exchange Online mailboxes with Litigation Hold

Get-Mailbox | Where {$_.LitigationHoldEnabled -match "True"} | FT Alias , lit*
Alias   LitigationHoldEnabled LitigationHoldDate    LitigationHoldOwner LitigationHoldDuration
-----   --------------------- ------------------    ------------------- ----------------------
Adele                    True 11/23/2016 2:52:34 PM George@o365info.com   6000.00:00:00         
bob                      True 12/11/2016 1:20:09 PM George@o365info.com   6000.00:00:00         
Depeche                  True 2/3/2016 2:29:08 PM   Bradp@o365pilot.com   970.00:00:00

Display information about Exchange Online mailboxes with In-place Hold

Get-Mailbox | Where {$_.InplaceHolds -ne $null} | FT Name,Alias,InPlaceHolds
Name     Alias    InPlaceHolds                              
----     -----    ------------                              
Angelina Angelina {0e9a2a3160464d49a656127020a7c11a}        
Eyal200  Eyal200  {UniHd0bcaafd-c284-4bae-b46f-ef049559d45a}

Display Exchange Online mailboxes with Audit enabled

Get-Mailbox | Where {$_.AuditEnabled -eq "$True"} | FL Name,Alias,Audit*
Name             : Adele
Alias            : Adele
AuditEnabled     : True
AuditLogAgeLimit : 90.00:00:00
AuditAdmin       : {Update, Copy, Move, MoveToDeletedItems...}
AuditDelegate    : {Update, Move, MoveToDeletedItems, SoftDelete...}
AuditOwner       : {Update, Move, MoveToDeletedItems, SoftDelete...}
 
Name             : bob
Alias            : bob
AuditEnabled     : True
AuditLogAgeLimit : 90.00:00:00
AuditAdmin       : {Update, Copy, Move, MoveToDeletedItems...}
AuditDelegate    : {Update, Move, MoveToDeletedItems, SoftDelete...}
AuditOwner       : {Update, Move, MoveToDeletedItems, SoftDelete...}

Display Exchange Online mailboxes with E-mail forwarding enabled for an internal email address

Get-Mailbox | Where {$_.ForwardingAddress -ne $null}| Select DisplayName,Alias,ForwardingAddress ,ForwardingSmtpAddress
DisplayName            Alias       ForwardingAddress          ForwardingSmtpAddress  
-----------            -----       -----------------          ---------------------  
Angelina Jolie         Angelina    Eyal                       smtp:bradp@o365info.com
DMARC and Spoof E-mail DMARC-Spoof DMARC Report- dmarcian.com                        

Display Exchange Online mailboxes with E-mail forwarding enabled for an external email address

Get-Mailbox | Where {$_.ForwardingSmtpAddress -ne $null} | Select DisplayName,Alias,ForwardingAddress ,ForwardingSmtpAddress
DisplayName    Alias    ForwardingAddress ForwardingSmtpAddress   
-----------    -----    ----------------- ---------------------   
Angelina Jolie Angelina Eyal              smtp:bradp@o365info.com 
Bob marley     bob                        smtp:edron789@gmail.com

Display Exchange Online mailboxes, which doesn’t appear in the GAL

Get-Mailbox | Where {$_.HiddenFromAddressListsEnabled -eq $True} | FT Name,Alias,HiddenFromAddressListsEnabled
Name                                                         Alias                                                        HiddenFromAddressListsEnabled
----                                                         -----                                                        -----------------------------
DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852}                          True
Elvis                                                        Elvis                                                                                 True

Display Exchange Online mailboxes that have an Archive

Get-Mailbox | Where {$_.ArchiveStatus -eq 'Active'} | FT Alias,RecipientTypeDetails,ArchiveStatus
Alias  RecipientTypeDetails ArchiveStatus
-----  -------------------- -------------
Alicia UserMailbox          Active       
bradp  UserMailbox          Active       
mord   UserMailbox          Active

Display Exchange Online mailboxes that have an Archive

Get-Mailbox | Where {$_.ArchiveStatus -ne 'Active'} | FT Alias,RecipientTypeDetails,ArchiveStatus

Or

Get-Mailbox | Where {$_.ArchiveStatus -ne 'none'} | FT Alias,RecipientTypeDetails,ArchiveStatus
Alias                                                        RecipientTypeDetails ArchiveStatus
-----                                                        -------------------- -------------
Adele                                                        UserMailbox          None         
admin                                                        UserMailbox          None         
Angelina                                                     UserMailbox          None         
Aretha                                                       UserMailbox          None         
Beatles                                                      UserMailbox          None

Display “Exchange Online user’s mailboxes,” with a specific “Department” value

Get-User | Where {$_.Department -eq "Sales"} |FT DisplayName,Department
DisplayName        Department
-----------        ----------
Brad Pitt          Sales     
Christina Aguilera Sales

Display “Exchange Online user’s mailboxes,” with a specific “Department” value | Department X or Department Y

Get-User | Where {($_.Department -eq "Sales") -or ($_.Department -eq "Marketing")} | Select DisplayName,Department | Sort Department
DisplayName        Department
-----------        ----------
Beatles the        Marketing 
Beyonce            Marketing 
Craig David        Marketing 
Brad Pitt          Sales     
Christina Aguilera Sales

Display “Exchange Online user’s mailboxes,” with a specific “Department” value and specific “Title” value

Get-User | Where {($_.Department -eq "Sales") -and ($_.Title -eq "Manager")} | FT DisplayName,Department,Title
DisplayName Department Title  
----------- ---------- -----  
Brad Pitt   Sales      Manager

Display “Exchange Online user’s mailboxes,” with a specific “Department” value | Department X or Department Y + specific Title value

Get-User | Where {($_.Department -eq "Sales") -or ($_.Department -eq "Marketing") -and ($_.Title -eq "Manager")} | FT DisplayName,Department,Title
DisplayName Department Title  
----------- ---------- -----  
Brad Pitt   Sales      Manager

Display “Exchange Online user’s mailboxes,” with a specific “Department” value | Department name start with a specific string

Get-User | Where {$_.Department -like "Sales*"} | FT DisplayName,Department
DisplayName        Department
-----------        ----------
Aretha Franklin    Sales UK  
Brad Pitt          Sales     
Christina Aguilera Sales     
Elvis Preslay      Sales USA

Display “Exchange Online user’s mailboxes,” that their Country or region is “not equal” to a specific Country or Region value

Get-User | Where {$_.CountryOrRegion -ne "USA"} | FT DisplayName,CountryOrRegion
DisplayName                        CountryOrRegion
-----------                        ---------------
Aretha Franklin                    Israel         
Beatles the                        United Kingdom 
Billy                              United Kingdom 
Bob marley                         Israel         
Brad Pitt                          Australia

Display Exchange Online mailboxes that were created after a specific date.

Get-Mailbox | Where-Object {$_.WhenCreated –gt "11/10/2016"} | FT DisplayName,WhenCreated
DisplayName     WhenCreated           
-----------     -----------           
Aretha Franklin 12/18/2016 9:01:58 AM 
Bob marley      11/17/2016 7:41:32 PM 
Demi Lovato     12/13/2016 1:23:08 PM 
Rihanna         12/13/2016 1:22:21 PM 
Shared-MB06     11/28/2016 3:31:46 PM 
Shared-MB07     11/28/2016 3:32:30 PM

Display Exchange Online mailboxes that were created during the last X minutes, hours, days, months etc.

Get-Mailbox | Where {$_.WhenCreated –ge ((Get-Date).Addminutes(-160))} | FT DisplayName,WhenCreated
Get-Mailbox | Where {$_.WhenCreated –ge ((Get-Date).AddHours(-40))} | FT DisplayName,WhenCreated
Get-Mailbox | Where {$_.WhenCreated –ge ((Get-Date).Adddays(-2))} | FT DisplayName,WhenCreated
Get-Mailbox | Where {$_.WhenCreated –ge ((Get-Date).AddMonths(-2))} | FT DisplayName,WhenCreated
Get-Mailbox | Where {($_.WhenCreated).Month –eq 8} | FT DisplayName,WhenCreated
Get-Mailbox | Where {$_.WhenCreated –ge ((Get-Date).AddYears(-2))} | FT DisplayName,WhenCreated

Display Exchange Online mailboxes, that were created before X Days, Months ago

Get-Mailbox | Where {$_.WhenCreated –le ((Get-Date).Adddays(-40))} | FT DisplayName,WhenCreated
Get-Mailbox | Where {$_.WhenCreated –le ((Get-Date).AddMonths(-2))} | FT DisplayName,WhenCreated

Display Exchange Online mailboxes, which was accessed (user login to the mailbox) by the user in the last X minutes.

Get-Mailbox | Get-MailboxStatistics| Where-Object {$_.LastLogonTime –ge ((Get-Date).Addminutes(-160))} | FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {$_.LastLogonTime –ge ((Get-Date).AddHours(-40))} | FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {$_.LastLogonTime –ge ((Get-Date).Adddays(-30))} | FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {$_.LastLogonTime –ge ((Get-Date).AddMonths(-2))} | FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {($_.LastLogonTime).Month –eq 8}| FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {$_.LastLogonTime –ge ((Get-Date).AddYears(-2))} | FT DisplayName,LastLogonTime
Get-Mailbox | Get-MailboxStatistics| Where-Object {($_.LastLogonTime).Year –eq 2016}| FT DisplayName,LastLogonTime -Autosize

Display Exchange Online mailboxes, which was NOT accessed (user did not log in to the mailbox) by the user in the last X Mounts.

Get-Mailbox | Get-MailboxStatistics | Where-Object {$_.LastLogonTime –le ((Get-Date).AddMonths(-2))}| FT DisplayName,LastLogonTime -Autosize
Get-Mailbox | Get-MailboxStatistics | Where-Object {$_.LastLogonTime –le ((Get-Date).AddYears(-2))}| FT DisplayName,LastLogonTime -Autosize

 

• Manage Office 365 Users Passwords

Set Password never expired for Office 365 user

Set-MsolUser –UserPrincipalName "John@o365info.com" -PasswordNeverExpires $True

Disable Password never expired option for a Office 365 user

Set-MsolUser –UserPrincipalName "John@o365info.com" -PasswordNeverExpires $False

Set Password never expired for ALL Office 365 users (Bulk Mode)

Get-MsolUser | Set-MsolUser –PasswordNeverExpires $True

Re-enable Password expired (The Default) for ALL Office 365 users (Bulk Mode)

Get-MsolUser | Set-MsolUser –PasswordNeverExpires $False

Set a Predefined Password for Office 365 user

Set-MsolUserPassword -UserPrincipalName "John@o365info.com" -NewPassword "ww#322x" -ForceChangePassword $False

Set a Predefined Password for all Office 365 users (Bulk mode)

Get-MsolUser |%{Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword "Abc#45" -ForceChangePassword $False}

Set a Predefined Password for Office 365 users imported from a CSV File

Get-MsolUser | Select UserPrincipalName  | Export-CSV "C:\Temp\o365users.csv"
Import-CSV "C:\Temp\o365users.csv" |%{ Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword AbcAs123 -ForceChangePassword $False}

Set a Temporary Password for a specific user

Set-MsolUserPassword -UserPrincipalName "John@o365info.com" -NewPassword ww@322x -ForceChangePassword $True

Set a Temporary Password for all Office 365 users (Bulk Mode)

Get-MsolUser | Set-MsolUserPassword -NewPassword ww#322x -ForceChangePassword $True

Set Office 365 Password Policy

Set-MsolPasswordPolicy -DomainName o365info.com -NotificationDays 15 -ValidityPeriod 180

Set Office 365 Password Policy

Get-MsolUser | Select UserPrincipalName,PasswordNeverExpires

Set Office 365 Password Policy

Get-MsolPasswordPolicy –DomainName  o365info.com

 

• Manage Email address

Replacing existing primary E-mail address – Method 1 (Not Recommend)

Set-Mailbox Bob -EmailAddress "BobNewEmail@o365info.com"

Replacing existing primary E-mail address – Method 2

Set-Mailbox Bob -WindowsEmailAddress "BobNewEmail@o365info.com"

Add Proxy E-mail address

Set-Mailbox Angelina -EmailAddresses @{ add="Angelina-Alias11@o365info.com" }
Set-Mailbox Angelina -EmailAddresses @{"+"=" Angelina-Alias11@o365info.com"}

Add Proxy E-mail address

Set-Mailbox Angelina -EmailAddresses @{ add="Angelina-Alias11@o365info.com","Angelina-Alias12@o365info.com" }

Add Primary SMTP E-mail address

Set-Mailbox -Identity Christina -EmailAddresses @{ add="SMTP:" + "New-Email@o365info.com" }

Add or update SIP address

Set-Mailbox Angelina -EmailAddresses  SIP:Angelina@o365info.com

Add or update x500 E-mail address

$User=Get-Mailbox John
$User.EmailAddresses+="X500:/O=ORG /OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=XX"
Set-Mailbox John –EmailAddresses $User.EmailAddresses

Updating Exchange Online mailbox properties in the directory synchronization environment or the Exchange Hybrid environment

Set-RemoteMailbox John -EmailAddresses Jhon@o365info.com -EmailAddressPolicyEnabled $false

Add a new Proxy E-mail address using specific domain name suffix

$Domainsuffix = Read-Host "Type the name of the Domain name suffix"
$AllMailboxes = Get-Mailbox -ResultSize Unlimited
Foreach ($Mailbox in $AllMailboxes) {
# Creating NEW E-mail address that contracted in the following way: Take the existing recipient Alias name + use the NEW Domain name as a domain suffix + “Bind” the Alias name + the NEW Domain name suffix.
$NewAddress = $Mailbox.Alias + "@$Domainsuffix"
# “Store” all existing E-mail addresses + add the NEW E-mail address as an additional E-mail address.
$Mailbox.EmailAddresses += $NewAddress
# Assign the NEW E-mail address to the existing Exchange Online recipient
Set-Mailbox -Identity $Mailbox.Alias -EmailAddresses $Mailbox.EmailAddresses #-whatif 
}

Add a new Proxy E-mail address using specific domain name suffix

Foreach ($Mailbox in $AllMailboxes) {
# Creating NEW E-mail address that contracted in the following way: Take the existing recipient Alias name + use the NEW Domain name as a domain suffix + “Bind” the Alias name + the NEW Domain name suffix.
$NewAddress = $Mailbox.Alias + "@o365pilot.com"
Set-Mailbox -Identity $Mailbox.Alias -WindowsEmailAddress $NewAddress #-whatif
}

Replace Primary E-mail Address with a NEW Primary E-mail address stored in a CSV file

$Recipients = Import-Csv C:\Temp\Recipient-E-mail-addresses.csv
Foreach ($Mailbox in $Recipients) {
Set-Mailbox -Identity $Mailbox.Recipient -EmailAddresses $Mailbox.PrimaryEmail,$Mailbox.AliasEmail # -WhatIf
}

Replace Primary E-mail Address with a NEW Primary E-mail address stored in a CSV file

$Recipients = Import-Csv C:\Temp\Recipient-E-mail-addresses.csv
Foreach ($Mailbox in $Recipients) {
Set-Mailbox -Identity $Mailbox.Recipient -EmailAddresses @{ Add=$Mailbox.AliasEmail} # -WhatIf
}

Add multiple Proxy E-mail address – importing from a CSV file

Import-Csv C:\temp\Recipient-Proxy-E-mail-addresses.csv | ForEach-Object {
$Recipient = $_.Recipient
$ProxyAddresses = $_.AliasEmail -split ';'
Set-Mailbox -Identity $Recipient -EmailAddresses @{ add=$ProxyAddresses }

Mixture of commands for $AllMailboxes

$AllMailboxes = Get-Mailbox -ResultSize Unlimited
$AllMailboxes = Get-MailBox -Filter '(RecipientTypeDetails -eq "UserMailbox")'
$AllMailboxes = Get-recipient -ResultSize Unlimited
$AllMailboxes = Get-recipient -ResultSize Unlimited | Where {$_.Capabilities -nq "MasteredOnPremise"}
$AllMailboxes = Get-Mailbox | Where {{$_.CustomAttribute1 -eq 'TestMailbox'}

Replace Primary E-mail address Domain name suffix with a NEW Domain name suffix (Bulk mode)

$AllMailboxes = Get-Mailbox -ResultSize Unlimited
Foreach ($Mailbox in $AllMailboxes){
# Creating NEW E-mail address that contracted in the following way: Take the existing recipient Alias name + use the NEW Domain name as a domain suffix + “Bind” the Alias name + the NEW Domain name suffix.
$NewAddress = $Mailbox.Alias + "@o365pilot.com"
Set-Mailbox -Identity $Mailbox.Alias -WindowsEmailAddress $NewAddress #-whatif
}

 

• Provisioning Office 365 user and export information from Active Directory

Display or export, all of the Active Directory users that located in a specific OU

Get-ADUser -LDAPfilter '(name=*)' -searchBase {OU=test,DC=o365info,dc=local}
$usersfromOU = Get-ADUser -LDAPfilter '(name=*)' -searchBase {OU=test,DC=o365info,dc=local}
$usersfromOU | export-csv "C:\usersbyOU.csv"

Display + Export information about Active Directory users from a specific department

$Users = Get-AdUser -filter "department -eq '<name>'"

.

$aduserdep = Get-AdUser -filter "department -eq 'marketing'" -Properties City,Title,Department,GivenName,Surname
$aduserdep | export-csv "c:\aduserdep.csv"

 

• Managing Mailbox Time Zone and Language setting

Set Time Zone for a Mailbox

Set-MailboxRegionalConfiguration John -TimeZone "Pacific Standard Time"  

Set Time Zone + Language for a Mailbox

Set-MailboxRegionalConfiguration John -TimeZone "Pacific Standard Time" –Language en-US

Set Time Zone + Language + Date/Time Format for a Mailbox

Set-MailboxRegionalConfiguration John -TimeZone "Pacific Standard Time" –Language en-US -DateFormat "dd/MM/yyyy" -TimeFormat "h:mm tt" 

Set Time zone on ALL Mailboxes (Bulk Mode)

$Users = Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $users | %{Set-MailboxRegionalConfiguration $_.Identity -TimeZone "Pacific Standard Time" }

Set Time zone + Language to ALL Mailboxes (Bulk Mode)

$users = Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $users | %{Set-MailboxRegionalConfiguration $_.Identity -TimeZone "Pacific Standard Time" –Language en-US }

Correct Time Zone setting for Mailbox with wrong time zone (Bulk Mode)

$Mymailboxes = Get-Mailbox 
ForEach ($examinedmailbox in $Mymailboxes){ $regionalconfig = Get-MailboxRegionalConfiguration –identity $examinedmailbox.identity
if ($regionalconfig.timezone -ne "Pacific Standard Time" ){ Set-MailboxRegionalConfiguration -identity $examinedmailbox.identity -TimeZone "Pacific Standard Time" -confirm:$False } }

Display a list of time zones you can use

Get-ChildItem "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Time zones" | FL pschildname

Display information about Time Zone and Language for a specific user

Get-MailboxRegionalConfiguration John

Display information about Time Zone and Language for a specific user

$Users = Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $Users | Get-MailboxRegionalConfiguration 

 

• Manage Recycle Bin

Restore Deleted User account by using the User UPN

Restore-MsolUser -UserPrincipalName "user1@o365info.com" -AutoReconcileProxyConflicts -NewUserPrincipalName "user1@o365info.com"

Restore Deleted User account by using the User GUID

Restore-MsolUser -ObjectId b9e82087-ad92-4632-a219-d779c29d2edd -AutoReconcileProxyConFLicts -NewUserPrincipalName "user1@o365info.com"

Display a list of ALL deleted User accounts

Get-MsolUser -ReturnDeletedUsers | FL UserPrincipalName,ObjectID

Display information about Specific deleted User account

Get-MsolUser –ReturnDeletedUsers –SearchString "User1@o365info.com" | FL UserPrincipalName,ObjectID

Delete (Remove) Specific user account from the Recycle bin

Remove-MsolUser -ObjectId b9e82087-ad92-4632-a219-d779c29d2edd -RemoveFromRecycleBin –Force

Delete (Remove) ALL user account from the Recycle bin (Bulk Mode)

Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser  -RemoveFromRecycleBin –Force

 

• Manage Retention Policy and Tags

Apply Retention policy for a single Mailbox

Set-Mailbox John -RetentionPolicy "My Policy"

Remove Retention Policy from a single a Mailbox (set to Null)

$UserMailboxes = Get-Mailbox  -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | Set-Mailbox –RetentionPolicy "My Policy"

Apply Retention Policy to ALL Office 365 Mailbox’s (Bulk Mode)

Set-Mailbox John -RetentionPolicy $Null

Remove Retention Policy for a Mailbox Retention policy to ALL Office 365 Mailbox’s (Bulk Mode)

$UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | Set-Mailbox –RetentionPolicy $Null

Display the Retention Policy applied to a User Mailbox

Get-Mailbox John | FL RetentionPolicy

Display the Retention Policy applied to all Office 365 users Mailbox’s

Get-Mailbox -ResultSize Unlimited | where {$_.name -Notlike '*DiscoverySearchMailbox*'} | select Alias, RetentionPolicy

Set the number of days for Deleted items, Tag

Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention 100

Disable Deleted items Tag

Set-RetentionPolicyTag "Deleted Items" -RetentionEnabled $False

Set the number of days for Junk Email Tag

Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention 100

Create NEW tag for Sync Issues Folder

New-RetentionPolicyTag -Name "My Tag" -Type 'SyncIssues' -AgeLimitForRetention 120 -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $True

Run the Managed Folder Assistant for a specific Mailbox

Start-ManagedFolderAssistant John

Run the Managed Folder Assistant for all Office 365 Mailbox’s (Bulk Mode)

$UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | ForEach {span style="color: #cd00cd">Start-ManagedFolderAssistant $_.Identity}

Set Deleted items policy for 30 days for specific user

Get-Mailbox John | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30

Set Deleted items policy for 30 days for ALL user (Bulk)

Get-Mailbox -ResultSize Unlimited | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30

Display information about Deleted items policy for specific user

Get-Mailbox John |FL alias,RetainDeletedItemsFor

Display information about Deleted items policy for ALL users

Get-Mailbox -ResultSize Unlimited |FL alias,RetainDeletedItemsFor

 

• Manage Distribution Groups

Create NEW Distribution Group (use default settings)

New-DistributionGroup -Name "Sales USA"

Create NEW Distribution Group + set additional Distribution Group settings

New-DistributionGroup -Name "Sales USA" -DisplayName "Sales USA mail list" -Alias "SalesUSA" -PrimarySmtpAddress SalesUSA@o365info.com -ManagedBy Brad

Creating Distribution Groups by importing information from a CSV File

Import-CSV "C:\Temp\DL-Group.csv" | ForEach {New-DistributionGroup -Name $_.name -Type $_.Type}

Enable or disable Distribution Group to get E-mail from external senders

Set-DistributionGroup "Sales USA" -RequireSenderAuthenticationEnabled $False

Enable an external recipient to send E-mail to all Distribution Groups (bulk mode)

Get-DistributionGroup | Set-DistributionGroup -RequireSenderAuthenticationEnabled $False

Replace existing Distribution Group owner

Set-DistributionGroup -Identity "Sales USA" -ManagedBy Brad -BypassSecurityGroupManagerCheck

Adding additional owner’s to Distribution Group

Set-DistributionGroup "Sales USA" -ManagedBy @{Add='bob','brad'}

Set Distribution Group Primary E-mail address

Set-DistributionGroup "Sales UK" -PrimarySmtpAddress SalesUK@o365info.com

Set Distribution Group Primary E-mail address by importing information from a CSV file

$GroupList = Import-CSV "C:\temp\Distribution-Groups-information.csv"
ForEach ($group in $GroupList){
ForEach ($email in $GroupList){
}Set-DistributionGroup -BypassSecurityGroupManagerCheck -Identity $group.GroupName -PrimarySmtpAddress $email.email}

Add additional E-mail address to existing Distribution Group E-mail address

Set-DistributionGroup "Sales UK" -emailaddresses @{Add='SalesUK02@o365info.com','SalesUK02@o365info.com','SalesUK02@o365info.com'}

Replace (remove) existing Distribution Group Alias E-mail

Set-DistributionGroup "Sales UK" -emailaddresses 'SalesUK02@o365info.com', 'SalesUK03@o365info.com'

Remove existing Distribution Group Alias E-mail addresses

Set-DistributionGroup "Sales UK" -EmailAddresses @{Remove=' Sales01@o365info.com', ' Sales02@o365info.com' }

Hide Distribution Group from GAL (Global address list)

Set-DistributionGroup "Sales UK" -HiddenFromAddressListsEnabled $True

Set an existing Distribution Group to accept E-mail only from a specific sender

Set-DistributionGroup "Sales UK" –AcceptMessagesOnlyFrom Bradp@o365info.com,Angelina@o365info.com

Define a Distribution Group Moderator

Set-DistributionGroup "Sales UK" –ModeratedBy Bradp@o365info.com,Angelina@o365info.com

Send out of office reply for a Distribution Group

Set-DistributionGroup "Sales UK"SendOofMessageToOriginatorEnabled $True 

Assign “Send As” Permissions to Distribution Group

Add-RecipientPermission "Sales UK" -Trustee Brad -AccessRights SendAs -Confirm:$False

Add a user (recipient) to a Distribution Group

Add-DistributionGroupMember -Identity "Sales UK" -Member Bradp

Import Distribution Group members from a CSV File

$Userslist = Import-CSV "C:\Temp\Distribution-Groups-Members.csv"
ForEach ($User in $Userslist){
Add-DistributionGroupMember -Identity "Sales France" -Member $User.PrimarySmtpAddress}

Add user (recipient) to multiple distribution groups

$Variable = "<Distribution Group name>","<Distribution Group name>","<Distribution Group name>"
ForEach ($item in $Variable)
{Add-DistributionGroupMember -Identity $item –Member }

Import Distribution Group members from a CSV File

$Userslist = Import-CSV "C:\Temp\Distribution-Group-Users.csv"
ForEach ($User in $Userslist){
Add-DistributionGroupMember -Identity "Sales France" -Member $User.PrimarySmtpAddress}

Add to Distribution Group all the users whom their department is Sales*

$SalesUsers = Get-User | Where {$_.Department -like "Sales*"}
foreach ($User in $SalesUsers){
Add-DistributionGroupMember -Identity "<em>Sales </em>worldwide " -Member $User.name}

Add user to distribution groups that were created in the last 48 hours

$AllNewDistributionGroups = Get-DistributionGroup | Where {$_.WhenCreated –ge ((Get-Date).AddHours(-48))}
ForEach ($Group in $AllNewDistributionGroups){
Add-DistributionGroupMember -Identity $Group.name –Member Bradp}

Display all Distribution Groups list + details

Get-DistributionGroup

Display Distribution Group Members

Get-DistributionGroupMember "Sales France"

Count the number of Distribution Group members

(Get-DistributionGroupMember "IT").Count

Display list of Distribution Groups with specific Email Domain

Get-DistributionGroup | Where {$_.emailaddresses –like "*o365info.com*"} | FT -Property Name,Alias,EmailAddresses -Autosize

Get a list of Distribution Groups, that was created in the last 2 weeks

Get-DistributionGroup | Where {$_.WhenCreated –ge ((Get-Date).Adddays(-14))} | FT DisplayName,WhenCreated

Display all Distribution Groups which their owner (managed by) is user X

Get-DistributionGroup | Where {$_.ManagedBy  -like "*adele*"} | FT DisplayName,ManagedBy

Display all Distribution Groups which have a moderator

Get-DistributionGroup  | Where {$_.ModeratedBy -notlike "$null"} | FT DisplayName,ManagedBy

Display all Distribution Groups that are synchronized from On-Premise Active Directory

Get-DistributionGroup | Where {$_.IsDirSynced  -eq $true} | FT DisplayName, IsDirSynced

Display Distribution Groups that accept E-mail from external recipients

Get-DistributionGroup | Where {$_.RequireSenderAuthenticationEnabled -eq $True} | FT DisplayName,RequireSenderAuthenticationEnabled

Display Distribution Groups that doesn’t accept E-mail from external recipients

Get-DistributionGroup | Where {$_.RequireSenderAuthenticationEnabled -eq $False } | FT DisplayName,RequireSenderAuthenticationEnabled

Get information about Distribution Group membership of a specific user

$User = read-host "User Name"
$UserDName = (Get-Mailbox $User).name
"The User " + $User + " is a member of the following Distribution Groups:"
ForEach ($DistributionGroup in Get-Distributiongroup -resultsize unlimited){
if ((Get-Distributiongroupmember $DistributionGroup.identity | select -expand name) -contains $UserDName)
{$DistributionGroup.name}}

Delete (Remove) a Distribution Group

Remove-DistributionGroup "Sales USA"

Remove a member from a Distribution Group

Remove-DistributionGroupMember -Identity "Sales USA" -Member "Bob"

Remove user from all the Distribution Groups which he is a member

$DistributionGroups = Get-Distributiongroup -resultsize unlimited
$UserDName = read-host "Enter User Name"
$UserDName = (Get-Mailbox $User).name
"Searching which groups " + $User + " is a member of and removing membership..."
ForEach ($Group in $DistributionGroups){
if ((Get-Distributiongroupmember $Group.Name | select -expand name) -contains $UserDName){
write-host "Removing user from group '$Group'"
Remove-DistributionGroupMember -Identity "$Group" -Member "$UserDName" -Confirm:>$false}}

Remove all members from a Distribution Group

$DistributionGroupMember = Get-DistributionGroupMember "IT"
ForEach ($member in $DistributionGroupMember){
Remove-DistributionGroupMember -Identity IT –Member $member.name -Confirm:$false}

Copy members from Distribution Group to a security group

$Members = Get-DistributionGroupMember -id "<Name of the source group>"
ForEach ($Member in $Members){
Add-DistributionGroupMember -Identity "<Name of the destination security group>" -Member $Member.name}

Extract Distribution Group member’s, and assign Full access permissions for each group member

$DistributionGroupName = Get-DistributionGroupMember "Sales France"
ForEach ($Member in $DistributionGroupName){
Add-MailboxPermission -Identity "Bradp" -User $Member.name -AccessRights 'FullAccess' -InheritanceType all}

Export information to Text FilePowerShell command Example

Get-DistributionGroup | Out-File "c:\temp\DistributionGroups.TXT"

Export information to CSV FilePowerShell command Example

Get-DistributionGroup | Export-CSV "c:\temp\DistributionGroups.CSV" –NoTypeInformation -Encoding UTF8

Export information to HTML File

Get-DistributionGroup | ConvertTo-Html "c:\temp\DistributionGroups.HTML"

Exporting information about Distribution Group members to a csv file

$Groups = Get-DistributionGroup -ResultSize Unlimited 
Foreach ($Group in $Groups){     
 $Members = Get-DistributionGroupMember -Identity $($Group.PrimarySmtpAddress)
 Foreach ($Member in $Members) {
 Out-File -FilePath "c:\temp\DistributionGroupMember.csv" -InputObject "$($Group.DisplayName),$($Member.DisplayName),$($Member.PrimarySMTPAddress)" -Encoding UTF8 -append } }

 

• Exchange Online – Display and Export information

Display List of all Mailbox’s type

Get-Mailbox

Adjustments & Customizations Filter the display output details

Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'}

Display List of all Mailbox’s Summery

Get-User | Group RecipientTypeDetails

Display List of office 365 Users Mailbox’s

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name,Alias

Display List of Room Mailbox’s

Get-MailBox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name,Alias

Display List of Equipment Mailbox’s

Get-MailBox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select Name,Alias

Display List of Shared Mailbox’s

Get-MailBox -Filter '(RecipientTypeDetails -eq "SharedMailbox")'  | Select RecipientTypeDetails,Name,Alias

Count the Mailbox’s number

(Get-Mailbox -ResultSize Unlimited).Count

Display ALL recipients Primary + Alias Email Address + SIP Address

Get-Mailbox -ResultSize Unlimited |FL EmailAddresses

Adjustments & Customizations Filter the display output details

Get-Mailbox -ResultSize Unlimited | Where {$_.name -Notlike '*DiscoverySearchMailbox*'} |FL EmailAddresses

Display every Alias for each recipients + Count Alias

Get-Mailbox | FL name, @{name="count";expression={[array]($_.EmailAddresses).Count}},EmailAddresses

Display Primary + Alias Email Address + SIP Address for specific Mailbox

Get-Mailbox John | Select -Expand EmailAddresses Alias

Display Office 365 users UPN names

Get-MsolUser | Select DisplayName,UserPrincipalName

Find Office 365 users that have UPN With specific Domain name suffix

Get-MsolUser -DomainName o365info.com | FL UserPrincipalName

Find Office 365 users that have UPN With specific Domain name suffix

Get-Mailbox | Where {$_.EmailAddresses -like "*o365info.com*"} | FL  Name,Alias,EmailAddresses

Find Distribution Groups Email Addresses that have specific Domain name suffix

Get-DistributionGroup | Where {$_.EmailAddresses -like "*o365info.com*"} | FL  Name,Alias,EmailAddresses

Find Contacts Email Addresses that have specific Domain name suffix

Get-Mailcontact | Where {$_.EmailAddresses -like "*o365info.com*"} | FL  Name,Alias,EmailAddresses

Find Mailbox’s Email Addresses that have specific Alias

Get-Mailbox | Where {$_.EmailAddresses -like "*John*"} | FL  Name,Alias,EmailAddresses

Find Distribution Groups Email Addresses that have specific Alias

Get-DistributionGroup | Where {$_.EmailAddresses -like "*John*"} | FL  Name,Alias,EmailAddresses

Find Contacts Email Addresses that have specific Alias

Get-Mailcontact | Where {$_.EmailAddresses -like "*John*"} | FL  Name,Alias,EmailAddresses

Find Email Addresses that have specific Alias + specific Domain name suffix

Get-Mailbox | Where {$_.Name -like "*John*" -and $_.EmailAddresses -like "*o365info.com*"} | FL  Name,Alias,EmailAddresses
Get-Mailbox | Where {$_.UsageLocation -like "*US*"} |FL Name,Alias,EmailAddres,UsageLocation

View Mailbox Statistics
Display information about mailbox size (Mailbox Statistics)

Get-MailboxStatistics John | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount

Display information about ALL of existing mailbox size (Bulk Mode)

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount

Display information about specific folder size

Get-MailboxStatistics John -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder

Information about mailbox Quotas size
View all Quotas assigned to a single Mailbox

<Get-Mailbox John | FL *Quota

View all Quotas assigned to ALL Mailbox’s

Get-Mailbox -ResultSize Unlimited | FL DisplayName,Alias,*Quota

View all Quotas assigned to a single Archive Mailbox

Get-MailboxStatistics John -Archive | FL DisplayName,Alias,*Quota

View Statistic of all Archive Mailboxes

Get-Mailbox  -Archive -ResultSize Unlimited | Get-MailboxStatistics -Archive | Select DisplayName,StorageLimitStatus,@{name="TotalItemSize (MB)";expression={[math]::Round(($_.TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{name="TotalDeletedItemSize (MB)";expression={[math]::Round(($_.TotalDeletedItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},ItemCount,DeletedItemCount | Sort "TotalItemSize (MB)" -Descending

Display list of Active mailboxes and users

Get-Mailbox -Resultsize unlimited | Get-MailboxStatistics | Where {$_.lastlogontime -ne $Null} | Select Displayname

Display list inactive Mailbox accounts in Office 365

Get-mailbox -Resultsize unlimited | Get-MailboxStatistics | Select Displayname,Lastlogontime | Sort-Object LastLogonTime

Display Mail recipients
Display list of Distribution Groups

Get-DistributionGroup | FL Name,DisplayName,GroupType,PrimarySmtpAddress

Display list of Mail contacts

Get-MailContact

Export information about Mailbox’s to file (CSV Format)
Export User Mailbox’s information

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV  "C:\Info\o365-User-Mailbox.csv"

Export Room Mailbox’s information

Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV "C:\Info\o365-Room-Mailbox.csv"

Export Equipment Mailbox’s information

Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV "C:\Info\o365-Equipment-Mailbox.csv"

Export Shared Mailbox’s information

Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV "C:\Info\o365-Shared-Mailbox.csv" -NoTypeInformation

Export information about mailboxes content (folders, items in folder etc.)

Get-Mailbox | Select-Object alias | ForEach-Object {{Get-MailboxFolderStatistics -Identity $_.alias | Select Identity,ItemsInFolder,FolderSize} | Export-CSV "C:\Info\o365-Export-Mailbox-Contents.csv" -NoTypeInformation

Export information about mailboxes LastLogonTime + LastLogoffTime

Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics | Select  DisplayName,lastlogontime,lastlogofftime | Sort-Object DisplayName -descending | Export-CSV "C:\Info\o365-Export-Mailbox-LastLogon.csv" -NoTypeInformation

 

• Manage Folder Permission

Assign Folder Permission to Calendar folder (Calendar sharing)
Assign Publishing Editor Permission to Calendar Folder

None, Owner, PublishingEditor, Editor, PublishingAuthor, Author, NonEditingAuthor, Reviewer, Contributor
Add-MailboxFolderPermission John:\calendar  -AccessRight PublishingEditor -User Suzan -AccessRight PublishingEditor

Assign Publishing Editor permissions to specific user to all existing Calendars (Bulk Mode)

Get-Mailbox | ForEach-Object {Add-MailboxFolderPermission $_":\Calendar" -User John -AccessRights PublishingEditor}

Set the default Folder permission of calendar to: Publishing Editor

Set-MailboxFolderPermission John:\calendar –User default -AccessRights PublishingEditor

Set the default sharing permission for everyone in your organization to: Reviewer (Bulk Mode)

$AllMailboxs = Get-Mailbox -Resultsize Unlimited
Foreach ($user in $AllMailboxs)
{Set-mailboxfolderpermission –identity ($user.alias+':\calendar') –user Default –Accessrights Reviewer}

Assign Publishing Editor Permission to Calendar folder – Different languish

$id = "John"; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Add-MailboxFolderPermission $id -User Suzan -AccessRights PublishingEditor

Assign Folder permission to Contacts folder
Assign Publishing Editor Permission to Contacts Folder

Add-MailboxFolderPermission John:\contacts -AccessRight PublishingEditor -User Suzan

Set the default permission for Contacts folder to Publishing Editor

Set-MailboxFolderPermission John:\contacts -User default -AccessRights Editor

Display Folder permission (Calendar and Contacts)
Display calendar Folder permission

Get-MailboxFolderPermission John:\calendar

Adjustments & Customizations: Filter the display output details

Get-MailboxFolderPermission John:\calendar | Select FolderName, user, AccessRights

Display contacts Folder permission

Get-MailboxFolderPermission John:\contacts

Adjustments & Customizations: Filter the display output details

Get-MailboxFolderPermission John:\contacts | Select FolderName, user, AccessRights

Export folder permission for all of the recipients ( Bulk mode)

Get-Mailbox | Get-MailboxFolderPermission | Export-CSV "c:\temp\users.csv"

Remove folder permissions
Remove Permission from a Calendar folder for a specific user

Remove-MailboxFolderPermission John:\calendar -User Suzan

Adjustments & Customizations: Remove the prompt for conformation

Remove-MailboxFolderPermission John:\calendar -User Suzan -Confirm:$false

Remove Permission from a contacts folder for a specific user

Remove-MailboxFolderPermission John:\contacts -User Suzan

Adjustments & Customizations: Remove the prompt for conformation

Remove-MailboxFolderPermission John:\contacts -User Suzan -Confirm:$False

Remove permission for a specific user from all Calendars (Bulk Mode)

Get-Mailbox | ForEach-Object {Remove-MailboxFolderPermission $_":\Calendar" -User John} -Confirm:$False

Assign Folder permissions | Advanced
Assign Folder Permissions to specific mailbox folder

Add-MailboxFolderPermission -Identity John:\inbox\Folder-A -user Suzan -AccessRights Reviewer

Assign Recursive Shared Folder Permissions

ForEach($f in (Get-MailboxFolderStatistics Suzan | Where { $_.FolderPath.Contains("/") -eq $True } ) ){
$fname = "Suzan:" + $f.FolderPath.Replace("/","\"); Add-MailboxFolderPermission $fname -User John -AccessRights Reviewer
Write-Host $fname
Start-Sleep -Milliseconds 1000}

 

• Disable Access to Service (protocol)

Disable OWA Access
Disable User access to OWA

ActiveSync, MAPI, POP3/IMAP, HTTPS
Set-CASMailbox John -OWAEnabled $False

Disable access to OWA for all Office 365 users (Bulk Mode)

Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -OWAEnabled $False

Disable POP3/IMAP4 Access
Disable User access to POP3/IMAP4

Set-CASMailbox John -imapenabled $False -popenabled $False 

Disable access to POP3/IMAP4 for all Office 365 users (Bulk Mode)

Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -PopEnabled $False -ImapEnabled $False  

Disable ActiveSync Access
Disable User access to ActiveSync

Set-CASMailbox John -ActiveSyncEnabled $False

Disable access to ActiveSync for all Office 365 users (Bulk Mode)

Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -ActiveSyncEnabled $False 

Disable Outlook AnyWhere Access
Disable User access to Outlook AnyWhere

Set-Set-CASMailbox John -MAPIEnabled $False

Disable access to Outlook AnyWhere for all Office 365 users (Bulk Mode)

Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -MAPIEnabled $False

Disable Office 365 user account
Disable Office 365 user account

Set-MsolUser -UserPrincipalName John@o365info.com -blockcredential $True

Disable Access to PowerShell
Disable Access to PowerShell

Set-User John -RemotePowerShellEnabled $False

Disable Access to PowerShell by using Filter – by Title

Get-User -ResultSize unlimited -Filter {(RecipientType -eq 'UserMailbox') -and (Title -like '*Temp-Employee*')} | Set-User -RemotePowerShellEnabled $False 

Display information
Display information about PowerShell status (Enabled or Disabled)

Get-User John | FL DisplayName,RemotePowerShellEnabled

Display information about User (Mailbox) Services

Get-CASMailbox John

Display information about ALL Users (Mailbox’s) Services

Get-CASMailbox | Where {$_.name -Notlike '*DiscoverySearchMailbox*'}

Display information about User (Mailbox) Services

<Get-MsolUser | FL DisplayName,BlockCredential

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

Reference:

o365info.com Manage Clutter by using PowerShell | Office 365
o365info.com How to create & publish Organizational Forms in Office 365
o365info.com Configure your WordPress site to send E-mail via Exchange Online (Office 365) 1-6
o365info.com Manage Litigation Hold by using PowerShell | Office 365
o365info.com Getting started with Office 365 PowerShell | Basic introduction | Part 1#4
o365info.com Manage Office 365 Users Passwords using PowerShell | Office 365
Microsoft Exchange View members of a dynamic distribution group
TechNet Exchange Automated replies and Distribution Groups
o365info.com Manage Distribution Groups by using PowerShell | 1#5
o365info.com Manage Mailbox Audit using PowerShell | Office 365
o365info.com Recovering deleted mail items using PowerShell cmdlets Search-Mailbox | 7#7
o365info.com  
o365info.com  
o365info.com  
o365info.com Manage Email address | Part 1#13