A few PowerShell (in Exchange Online) impressions summarized!

%3CLINGO-SUB%20id%3D%22lingo-sub-2068594%22%20slang%3D%22en-US%22%3EA%20few%20PowerShell%20(in%20Exchange%20Online)%20impressions%20summarized!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2068594%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Microsoft%20365%20and%20Exchange%20Online%20Friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20this%20article%20I%20have%20summarized%20a%20few%20tasks%20that%20I%20used%20on%20a%20project.%20This%20is%20certainly%20not%20an%20exhaustive%20summary%20when%20it%20comes%20to%20working%20with%20Exchange%20Online%2C%20I%20just%20wanted%20to%20summarize%20a%20few%20points.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20used%20the%20Visual%20Studio%20Code%20Editor%20for%20this%20configuration.%20But%20you%20are%20also%20very%20welcome%20to%20use%20the%20PowerShell%20ISE%2C%20just%20as%20you%20wish.%26nbsp%3BPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%26nbsp%3B%22%3CSPAN%3Ejourney%22%3C%2FSPAN%3E%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23The%20first%20two%20lines%20have%20nothing%20to%20do%20with%20the%20configuration%2C%20but%20make%20some%20space%20below%20in%20the%20black%20part%20of%20the%20VSCode%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-Location%20C%3A%5CTemp%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EClear-Host%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Bbe%26nbsp%3Bable%26nbsp%3Bto%26nbsp%3Binstall%26nbsp%3Bthe%26nbsp%3Bexchange%26nbsp%3Bonline%26nbsp%3Bmodule%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ESet-ExecutionPolicy%26nbsp%3BRemoteSigned%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Install%26nbsp%3Bthe%26nbsp%3Bexchange%26nbsp%3Bonline%26nbsp%3Bmanagement%26nbsp%3Bmodule%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EInstall-Module%26nbsp%3B-Name%26nbsp%3BExchangeOnlineManagement%26nbsp%3B-Verbose%26nbsp%3B-Force%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Update%26nbsp%3Bthe%26nbsp%3Bmodule%26nbsp%3B(if%26nbsp%3Bnecessary)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EUpdate-Module%26nbsp%3B-Name%26nbsp%3BExchangeOnlineManagement%26nbsp%3B-Verbose%26nbsp%3B-Force%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Connect%26nbsp%3Bto%26nbsp%3Bexchange%26nbsp%3Bonline%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EConnect-ExchangeOnline%26nbsp%3B-UserPrincipalName%26nbsp%3Badmin365%40yourdomain.onmicrosoft.com%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Is%26nbsp%3Ban%26nbsp%3Barchive%26nbsp%3Balready%26nbsp%3Bin%26nbsp%3Buse%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-Mailbox%26nbsp%3B%7C%26nbsp%3BWhere-Object%26nbsp%3B%7B%24_.ArchiveDatabase%26nbsp%3B-ne%26nbsp%3B%24null%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-Mailbox%26nbsp%3B%7C%26nbsp%3BWhere-Object%26nbsp%3B%7B%24_.ArchiveDatabase%26nbsp%3B-ne%26nbsp%3B%24null%7D%26nbsp%3B%7C%26nbsp%3BFormat-Table%26nbsp%3Bname%2C%26nbsp%3Barchivedatabase%2C%26nbsp%3Barchivename%2C%26nbsp%3Barchivequota%2C%26nbsp%3Barchivewarningquota%26nbsp%3B-AutoSize%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Run%26nbsp%3Bthis%26nbsp%3Bcommand%26nbsp%3Bto%26nbsp%3Benable%26nbsp%3Bthe%26nbsp%3Barchive%26nbsp%3Bmailbox%26nbsp%3Bfor%26nbsp%3Ba%26nbsp%3Bsingle%26nbsp%3Buser%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EEnable-Mailbox%26nbsp%3B-Identity%26nbsp%3B%22peter%40contosotom.ch%22%26nbsp%3B-Archive%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Run%26nbsp%3Bthis%26nbsp%3Bcommand%26nbsp%3Bto%26nbsp%3Benable%26nbsp%3Bthe%26nbsp%3Barchive%26nbsp%3Bmailbox%26nbsp%3Bfor%26nbsp%3Ball%26nbsp%3Busers%26nbsp%3Bin%26nbsp%3Byour%26nbsp%3Borganization%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-Mailbox%26nbsp%3B-Filter%26nbsp%3B%7BArchiveStatus%26nbsp%3B-Eq%26nbsp%3B%22None%22%26nbsp%3B-AND%26nbsp%3BRecipientTypeDetails%26nbsp%3B-eq%26nbsp%3B%22UserMailbox%22%7D%26nbsp%3B%7C%26nbsp%3BEnable-Mailbox%26nbsp%3B-Archive%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Note%3A%26nbsp%3BWhen%26nbsp%3Byou%26nbsp%3Bturn%26nbsp%3Bon%26nbsp%3Ban%26nbsp%3Barchive%2C%26nbsp%3Ba%26nbsp%3Bretention%26nbsp%3Bpolicy%26nbsp%3Bshould%26nbsp%3Balso%26nbsp%3Bbe%26nbsp%3Bconfigured%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Run%26nbsp%3Bthis%26nbsp%3Bcommand%26nbsp%3Bto%26nbsp%3Bdisable%26nbsp%3Bthe%26nbsp%3Barchive%26nbsp%3Bmailbox%26nbsp%3Bfor%26nbsp%3Ba%26nbsp%3Bsingle%26nbsp%3Buser%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EDisable-Mailbox%26nbsp%3B-Identity%26nbsp%3B%22peter%40contosotom.ch%22%26nbsp%3B-Archive%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Run%26nbsp%3Bthis%26nbsp%3Bcommand%26nbsp%3Bto%26nbsp%3Bdisable%26nbsp%3Bthe%26nbsp%3Barchive%26nbsp%3Bmailbox%26nbsp%3Bfor%26nbsp%3Ball%26nbsp%3Busers%26nbsp%3Bin%26nbsp%3Byour%26nbsp%3Borganization%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-Mailbox%26nbsp%3B-Filter%26nbsp%3B%7BArchiveStatus%26nbsp%3B-Eq%26nbsp%3B%22Active%22%26nbsp%3B-AND%26nbsp%3BRecipientTypeDetails%26nbsp%3B-eq%26nbsp%3B%22UserMailbox%22%7D%26nbsp%3B%7C%26nbsp%3BDisable-Mailbox%26nbsp%3B-Archive%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23This%26nbsp%3Bexample%26nbsp%3Breturns%26nbsp%3Ba%26nbsp%3Bsummary%26nbsp%3Blist%26nbsp%3Bof%26nbsp%3Ball%26nbsp%3Bdistribution%26nbsp%3Bgroups%26nbsp%3Bthat%26nbsp%3Bcan%26nbsp%3Bbe%26nbsp%3Bupgraded%26nbsp%3Bto%26nbsp%3BMicrosoft%26nbsp%3B365%26nbsp%3BGroups%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-EligibleDistributionGroupForMigration%26nbsp%3B-ResultSize%26nbsp%3Bunlimited%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23This%26nbsp%3Bexample%26nbsp%3Bcreates%26nbsp%3Bdevice%26nbsp%3Baccess%26nbsp%3Brules%26nbsp%3Bthat%26nbsp%3Bblocks%26nbsp%3Baccess%26nbsp%3Bfor%26nbsp%3BAndroid%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ENew-ActiveSyncDeviceAccessRule%26nbsp%3B-Characteristic%26nbsp%3BDeviceType%26nbsp%3B-QueryString%26nbsp%3B%22Android%22%26nbsp%3B-AccessLevel%26nbsp%3BBlock%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Bproof%20the%20rule%20has%20been%20created%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EGet-ActiveSyncDeviceAccessRule%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Bremove%26nbsp%3Bthe%26nbsp%3Brule%26nbsp%3Buse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ERemove-ActiveSyncDeviceAccessRule%26nbsp%3B-Identity%26nbsp%3B%22Android%26nbsp%3B(DeviceType)%22%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Bproof%20the%20rule%20has%20been%20removed%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-ActiveSyncDeviceAccessRule%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EI%20am%20absolutely%20aware%20that%20this%20is%20nothing%20spectacular.%20I%20just%20wanted%20to%20share%20a%20few%20impressions%20with%20you.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20Azure%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2068594%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Contributor

 

Hi Microsoft 365 and Exchange Online Friends,

 

In this article I have summarized a few tasks that I used on a project. This is certainly not an exhaustive summary when it comes to working with Exchange Online, I just wanted to summarize a few points.

 

I used the Visual Studio Code Editor for this configuration. But you are also very welcome to use the PowerShell ISE, just as you wish. Please start with the following steps to begin the "journey" (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the black part of the VSCode

Set-Location C:\Temp
Clear-Host

 

#To be able to install the exchange online module
Set-ExecutionPolicy RemoteSigned

#Install the exchange online management module
Install-Module -Name ExchangeOnlineManagement -Verbose -Force

#Update the module (if necessary)
Update-Module -Name ExchangeOnlineManagement -Verbose -Force

#Connect to exchange online
Connect-ExchangeOnline -UserPrincipalName admin365@yourdomain.onmicrosoft.com

#Is an archive already in use?
Get-Mailbox | Where-Object {$_.ArchiveDatabase -ne $null}
 
Get-Mailbox | Where-Object {$_.ArchiveDatabase -ne $null} | Format-Table name, archivedatabase, archivename, archivequota, archivewarningquota -AutoSize

#Run this command to enable the archive mailbox for a single user
Enable-Mailbox -Identity "peter@contosotom.ch" -Archive

#Run this command to enable the archive mailbox for all users in your organization
Get-Mailbox -Filter {ArchiveStatus -Eq "None" -AND RecipientTypeDetails -eq "UserMailbox"} | Enable-Mailbox -Archive

#Note: When you turn on an archive, a retention policy should also be configured

#Run this command to disable the archive mailbox for a single user   
Disable-Mailbox -Identity "peter@contosotom.ch" -Archive

#Run this command to disable the archive mailbox for all users in your organization
Get-Mailbox -Filter {ArchiveStatus -Eq "Active" -AND RecipientTypeDetails -eq "UserMailbox"} | Disable-Mailbox -Archive

#This example returns a summary list of all distribution groups that can be upgraded to Microsoft 365 Groups
Get-EligibleDistributionGroupForMigration -ResultSize unlimited

#This example creates device access rules that blocks access for Android
New-ActiveSyncDeviceAccessRule -Characteristic DeviceType -QueryString "Android" -AccessLevel Block

#To proof the rule has been created
Get-ActiveSyncDeviceAccessRule

#To remove the rule use
Remove-ActiveSyncDeviceAccessRule -Identity "Android (DeviceType)"

#To proof the rule has been removed
Get-ActiveSyncDeviceAccessRule
 
I am absolutely aware that this is nothing spectacular. I just wanted to share a few impressions with you.
 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies