EOP / Office 365: Connect and Use Powershell
The blog will explain the steps on how to connect to office 365 or Exchange online protection for the management using powershell of your desktop client computer.
Open powershell with Run as Administrator on your computer
Run the command to cache authentication
$Cred = Get-credential
This will popup authentication windows. Type your login id which is the User principal name and password.
Run the command to configure the powershell to use the office 365.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic –AllowRedirection
Verify and change the execution policy.
To verify run the command:
To change run the cmd
If your executionpolicy will be Restricted then you will see the below error:
Import-PSSession : Files cannot be loaded because the running of scripts is disabled on this system. Please provide a
valid certificate with which to sign the files.
As an example I ran the below command
Run the below command to disconnect the session:
To verify run the working command as mentioned below and you will see the below error
Error: The term ‘Get-Mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Microsoft MVP | Exchange Server