Using PowerShell with Office 365

Jun - 20 2022 | By

There are a variety of commands in PowerShell that you can use to make changes for individuals and for your entire organization

Below are the commands to issue in PowerShell to connect to your account, the user that signs in should be a Administrator for your Office 365 organization.

Use this command to connect – change to your email account with administrator rights. This command will bring up a Microsoft Modern Authentication prompt to sign into your account.  This sign in will focus on Exchange email capabilities of Microsoft 365.

Connect-ExchangeOnline -UserPrincipalName -ShowProgress $true

This command will attempt to connect to Office 365 with the credentials that you have provided.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ny-msg-02/powershell/ -Credential $LiveCred -Authentication Kerberos

This command will import the commands for Exchange management

Import-PSSession $Session

If this command generates an error similar to: Import-PSSession: Files cannot be loaded since running scripts has been disabled on this system. Provide a valid certificate with which to sign the files. If you receive this error you need to enable RemoteSigned using this command.

Set-ExecutionPolicy RemoteSigned

If you do not receive an error you can skip this command listed above.

To disconnect your PowerShell session from Office 365 use this command to sign you out.

Remove-PSSession $Session

Microsoft Documentation on Microsoft 365 with PowerShell