Connecting to Exchange Online with remote PowerShell from a Mac

Yes! it is finally possible to connect to Exchange Online from PowerShell installed on MacOS. I noticed some tweets about this being possible on Linux earlier in the week so I thought I’d re-visit testing it on MacOS. PowerShell remoting has been available in the MacOs version since powershell-6.0.0-alpha.15, but it didn’t include the ability to specify a “ConnectionUri’ as the endpoint – it only worked with server names and IP addresses. powershell-6.0.0-alpha.17 which was recently released now includes this functionality.

The first thing you need to do it download and install the latest release from here, you’ll want to download at least powershell-6.0.0-alpha.17

Screen Shot 2017-03-15 at 3.47.08 PM

Next launch PowerShell and confirm the version:

$PSVersionTable

Screen Shot 2017-03-15 at 4.31.53 PM

We are now ready to run establish our remote session. First let’s define our credentials:

$UserCredential = Get-Credential

Then create the session:

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

And finally, import that session:

Import-PSSession $Session

Screen Shot 2017-03-15 at 4.41.16 PM

Once connected you have all the Exchange Online cmdlets available to you:

Screen Shot 2017-03-15 at 4.46.02 PM

I haven’t thoroughly tested it yet, but I look forward to spending some time using it soon!

Share this?Print this pageEmail to someoneTweet about this on TwitterShare on LinkedInShare on FacebookDigg thisGoogle+Pin on PinterestShare on StumbleUponShare on Redditshare on TumblrBuffer this pageFlattr the author

Post navigation


Comments

  • Martin

    Thank you very much! At last i can leave MS totally 🙂 Works perfectly!!

  • Sascha

    Thanks for this post!

    First, I would like to inform you, that your command for creating the session contains an “a href”-tag, which produces an error.

    But even if I use the right command:

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

    I get an error:

    Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
    at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
    at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
    at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
    Abort trap: 6

    Do you know the reason for that? Thanks.

  • Chris

    Hi Sascha,

    Thanks for the info. I have corrected the code so you should be good to go, I just tested it and it works. I’m not entirely sure why you are receiving the error. Can you confirm the version of PowerShell you are running?

    Thanks,

    Chris

  • Edward Glasheen

    Any word on when PS (Mac) will be available for O365/SharePoint?

    Thanks,

    Ed

  • Chris

    Hi Edward,

    Thanks for the comment. Unfortunately, I don’t know what the current roadmap is for that, but I would venture to guess that we will see something in time. I’ll be sure to add any updated info here when it becomes available.

    Thanks,

    Chris

  • Amanda Debler

    Hi!

    I’ve updated to 6.0.0-beta.2, but still get this error when I run the New-PSSession command:

    New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error
    message : Client did not get proper response from server. For more information, see the about_Remote_Troubleshooting Help topic.
    At line:1 char:20
    + ... geSession = New-PSSession -ConfigurationName Microsoft.Exchange -Conn ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTranspor
    tException
    + FullyQualifiedErrorId : 1,PSSessionOpenFailed

  • Chris

    Hi Amanda,

    Thats an interesting error, are you able to resolve outlook.office365.com correctly? I haven’t been able to replicate the issue, but it does look like version v6.0.0-beta.3 is out so perhaps upgrading to that will help? It seems to work great for me.

    I’ll keep trying to replicate it and report back if I find anything.

    All the best,

    Chris

  • Steven

    Hi Chris,

    Thanks for the post. I seem to be doing fine however, once the cmdlets are loaded (or better yet, the module) I get no results from a cmdlet lie Get-Mailbox. Just a blank line and nothing happens. No output or any way for me to break out of that (ctrl-c). Any tips or suggestions on what could be wrong?

    Using PS: v6.0.0-alpha.18

  • Chris

    Hey Steven,

    I’ve never seen that before. Have you tried installing the latest build? It’s currently v6.0.0-beta.3, I wonder if that would help resolve your problem.

    Cheers,

    Chris

  • Holraven

    Hi Chris! I get the exact same error as Sascha, running MacOS 10.12.5 and PowerShell beta v6.0.0-beta.3 when trying to create the Session, leading to PowerShell crashing:

    Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Management.Automation.Remoting.PrioritySendDataCollection.Clear()
    at System.Management.Automation.Remoting.Client.BaseClientTransportManager.CloseAsync()
    at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.CloseAsync()
    at System.Management.Automation.Remoting.Client.BaseClientTransportManager.Finalize()
    Abort trap: 6

    Any more ideas?

  • Chris

    Hey Holraven,

    I’ve tried to replicate it on a few different machines without success. Could you describe how you are creating the session and after which commands you receive the error?

    Thanks,

    Chris

  • Tarigand

    I am getting the following error when running this command:

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

    New-PSSession : Unable to load DLL ‘libpsrpclient’: The specified module could not be found.
    (Exception from HRESULT: 0x8007007E)
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-PSSession], DllNotFoundException
    + FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.NewPSSessionCommand

  • Chris

    Hi Tarigand,

    I haven’t seen that before. What version of MacOS and PowerShell are you using and do other cmds work? eg. $PSVersionTable or Get-Process ?

    Cheers,

    Chris

  • Tony

    Hi.

    How does one get the Set-MsolUserPassword cmdlet?

    Thanks!

  • Chris

    Hi Tony,

    That cmdlet is part of the Azure AD PowerShell module which is not available for macOS or Linux yet. I expect (and hope!) that a macOS version will be available soon.

    Cheers,

    Chris

  • Andreas

    Hej

    I can connect to ExchangeOnline and load all commandos but when i Get-Mailbox or any “get” commandos execute i dont receive result or feedback from ExchangeOnline.

    Is there someone who knows the problem and has a solution for it

  • Chris

    Hi Andreas,

    What version of MacOS and PowerShell are you using and do other cmds work? eg. $PSVersionTable

    Could you send me a PowerShell transcript of what you are doing? i.e run ‘Start-Transcript’ when you start PowerShell, then connect to Exchange Online and once connected run ‘Stop-Transcript’. Remember to remove any sensitive info before sending or posting it.

    Thanks,

    Chris

  • Andreas

    Hej Chris

    MacOS: 10.12.6
    PowershellVersion : powershell v6.0.0-beta.4

    and here my Transcript log. I have changed my username with “somuser” , removed Username and Runas User.

    **********************
    Windows PowerShell transcript start
    Start time: 20170804095017
    Username:
    RunAs User:
    Configuration Name:
    Machine: (Unix 16.7.0.0)
    Host Application: /usr/local/microsoft/powershell/6.0.0-beta.4/powershell.dll
    Process ID: 2086
    PSVersion: 6.0.0-beta
    PSEdition: Core
    GitCommitId: v6.0.0-beta.4
    OS: Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64
    Platform: Unix
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    WSManStackVersion: 3.0
    **********************
    Transcript started, output file is /Users/somuser/PowerShell_transcript.itce-mac-and02.iwOMJhjU.20170804095017.txt
    PS /Users/somuser> $UserCredential = Get-Credential
    PS /Users/somuser> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection
    PS /Users/somuser> Import-PSSession $Session
    WARNING: The names of some imported commands from the module ‘tmp_ttigrmsk.c3n’ include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

    ModuleType Version Name ExportedCommands
    ———- ——- —- —————-
    Script 1.0 tmp_ttigrmsk.c3n {Add-AvailabilityA…

    PS /Users/somuser> get-mailbox -Identity somuser@somdomain.dk

    /Andreas

  • Chris

    Hey Andreas,

    I’m definitely seeing some interesting things with MacOS 10.12.6/ PowerShell v6.0.0-beta.4 as well. Just doing some more testing to see what I can come up with and will post back.

    Cheers,

    Chris

  • Andreas

    Hej Chris

    Thank you for help.

    I can ascertain at the problem was already in beta 3 and beta 2 and before.

    Cheers,
    Andreas

  • John

    Hey Chris,

    Using macOS 10.12.6 with 6.0.0.-beta.5 and getting the following error on the New-Session:

    PS /Users/john> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection

    New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand

  • Chris

    Hey John.

    Just tested it using the same builds and not seeing that issue. I wonder if this could be related to some missing pre-req. Have you installed OpenSSL, etc as instructed here: https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#macos-1012

  • Dana

    Hi Chris,

    I get the following error:$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection
    New-PSSession : [outlook.office365.com] Connecting to remote server
    outlook.office365.com failed with the following error message :
    MI_RESULT_FAILED For more information, see the about_Remote_Troubleshooting
    Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme….RemoteRunspace:Re
    moteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : 1,PSSessionOpenFailed

    Very basic knowledge, so I’m sure it is user error, using MacOS 10.12.6, Powershell v6.0.0-beta.7.

    Appreciate your help, this has been the best instruction I’ve been able to find.

    Best,
    Dana

  • Chris

    Hi Dana,

    Are you able to ping/resolve outlook.office365.com? What happens if you open terminal and type “ping outlook.office365.com” ?

    Thanks,

    Chris

  • Andreas

    Hej Chris and Dana

    I get the same error as Dana, since I have installed Powershell for Mac OS beta 7. I can easily ping outlook.office365.com. Så I think, that Is an bug.

    Regards Andreas

  • Anil

    Hi
    I am getting the same error…How to resolve this?

    New-PSSession : [outlook.office.com] Connecting to remote server
    outlook.office.com failed with the following error message : MI_RESULT_FAILED
    For more information, see the about_Remote_Troubleshooting Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme….RemoteRunspace:Re
    moteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : 1,PSSessionOpenFailed

    Thanks

  • Chris

    Hey Anil,

    What Uri are you connecting to? From the error it looks like outlook.office.com. Could you try outlook.office365.com?
    i.e “-ConnectionUri https://outlook.office365.com/powershell-liveid

    Thanks,

    Chris

  • Anil

    Hi Chris,

    I was trying using outlook.office.com to test. I just tried again – see the error below.

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection
    New-PSSession : [outlook.office365.com] Connecting to remote server
    outlook.office365.com failed with the following error message :
    MI_RESULT_FAILED For more information, see the about_Remote_Troubleshooting
    Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme….RemoteRunspace:Re
    moteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : 1,PSSessionOpenFailed

    I am on macOS Sierra 10.12.6

    Installed Power Shell using brew.

    Thanks
    Anil

  • Erick

    I’m getting the same error

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection
    New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message :
    MI_RESULT_FAILED For more information, see the about_Remote_Troubleshooting Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : 1,PSSessionOpenFailed

    I’m on Xubuntu 17.04 running Powershell version 6.0.0-beta.8

  • Chris

    Thanks for the info Erick – seems this is happening on Linux systems as well. I have not been able to replicate it myself, but I did notice yesterday that connecting to Exchange Online was so slow it was unusable.

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=""> <s> <strike> <strong>