Powershell: How to connect to Office 365 with Powershell

Powershell Header

You can simply manage and administrate Office 365 from your Powershell prompt or with your own Powershell scripts.

office365

Here is how you can connect to Office 365 with Windows PowerShell:

First create a object with your Windows Live Credentials. This command will open a Windows in which you can enter your Windows Live Credentials for your Office365 Accout. In my case tmauer@tmaurer.onmicrosoft.com and my password.

$LiveCred = Get-Credential

You can open a new Session:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Now join the session with:

Import-PSSession $Session

To close the Session:

Remove-PSSession $Session

Now if you join the PS session with Enter-PSSession you can now work online and run commands like Get-User. More about working with Powershell and Office 365 in the next posts.

Related Posts:

5 thoughts on “Powershell: How to connect to Office 365 with Powershell

  1. Hallo,

    ich versuche im Moment meinen Exchange Online Account einzurichten, verzweifel aber am Verbindungsaufbau zu den Microsoft Online Services.
    Mit welchen Zugangsdaten muss ich mich da einloggen? Mit den Daten des Administrators von Exchange Online oder einer LiveID oder …?

  2. Thank you. Was looking for one.. I’m using onmicrosoft 365 and ran into issue when I maxed out the powershell connections. I now close the session after I am done. :)

  3. Hi. Danke für die Anleitung.
    Ich möchte gerne die Kennwortrichtlinie Deaktivieren. Leider bekomme ich beim connect-MsolService CMDlet immer eine Fehlermeldung.

    Hast du einen Ahnung was da los sein kann?

    MFG,
    Martin

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>