Scripting things in Office 365.
Some Office 365 services require modules to be installed locally, whereas others use remote PowerShell sessions.
Microsoft have instructions on how to install modules or connect to services here: Connect PowerShell to Office 365 Services
The SharePoint module can also now be installed directly from PSGallery using:
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
In addition, the services which use remote sessions will require the script execution policy within PowerShell to be changed to RemoteSigned. This is done either globally with:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Or for the current user with:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
All scripts are provided as is without warranty of any kind, use them at your own risk.