Connect Office 365 with Windows PowerShell

Add permission

To run scripts in Windows PowerShell, we need to run the following command as an administrator. To do this we start the PowerShell as administrator (right mouse button and choose to run as administrator). This command only needs to be executed once.

PS C:\>

Set-ExecutionPolicy RemoteSigned

Establish connection

Now start a normal PowerShell without administrator privileges and execute the following commands:

Login with your Office 365 credentials

PS C:\>

$UserCredential = Get-Credential

To start the session execute:

PS C:\>

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

PS C:\>

Import-PSSession $Session

Check connection

To check if you are connected, you can print some mailbox information with:

PS C:\>


Close connection

If you are done, close the session with:

PS C:\>

Remove-PSSession $Session


Windows Docs - Connect to Exchange Online PowerShell

Windows Docs - Get-Mailbox


Bitte rechnen Sie 6 plus 2.