PowerShell connection from MacOS not working

Copper Contributor

I trying PowerShell 7 on MacOS and I have installed SharePoint Online Management Shell but the "Connect-SPOService" command is not found. 

 

Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

Microsoft.Online.SharePoint.PowerShell 16.0.20017.12000

14 Replies

@Bikash Maharjan 

 

I have found that my attempts to get PowerShell to work on MacOS have resulted in limited success.  Each time I try it, there seems to be slightly more functionality, but it really has a long way to go.  It's too frustrating at the moment to try and make it work, so for any PowerShell I just revert to my Windows 10 device for the time being.

@PeterRising Thanks for confirmation - I was wondering if it was just my setup. 

Hi @Bikash Maharjan , I run into the same or at least similar problem. Let me first explain why I want to use PowerShell end then explain the problem that I ran into (similar to your problem).

 

I don't have a PC, I work with a MacBookPro. What I want to do is setup scripts with help of PowerShell, to create Team sites with Teams plus a few dedicated Lists which I need to provide to customers in order to allow a PowerApp read/write data on that list.

 

Using latest OSX, I wanted to set up PowerShell for MacOS. Following all provided information in Microsoft Help docs:

- installed HomeBrew (succes),

- installed PowerShell v 7 (succes)

- imported various modules:

  • Teams (Succes)
  • AZ (Succes)
  • Microsoft.Online.SharePoint.PowerShell (???).

If I then run a get-help on 'connect*' I get:

  • Connect-AzAccount from module Az.Accounts

  • Connect-MicrosoftTeams from module MicrosoftTeams

So, apparently, while there is no sign that the SPO module was not successfully imported, it is not possible to connect to SPO. Hence when I run (with the variables set to the correct values)

"Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential"

I get the response:

"Connect-SPOService: The term 'Connect-SPOService' 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."

 

Now... what to do next? I already repeated the entire installation: no effect. So now I think about setting up PowerShell though Azure. Do you or anyone else have an idea how to do that? Help is much appreciated! 

@Bikash Maharjan I have spent several hours attempting to get this to work, to come to the same conclusion: the Install-Module command seems to work, but then doesn't seem to actually install what's needed.

 

In less than 5 minutes, I fired up Parallels and had everything working in Windows 10, doing exactly the same thing I was attempting in MacOS.

 

Is there some technical problem to be fixed by Microsoft?

@Jamesr2049 

 

This is more something for Apple to fix than Microsoft I think.

@PeterRising Indeed, Peter, I had the same problem, but at some point was informed by someone from PowerShell development that this is indeed not working. So, I made my Mac dual boot and installed a full Windows 10 using Bootcamp. Works perfect.

@Bikash Maharjan I just tried it again with Powershell installed via homebrew. I can install the Module Microsoft.Online.SharePoint.PowerShell and after exiting Powershell and running it again I get a full list of commands.

 

Powershell Commandlets.png

Unfortunately logging in results in an error:

 

 

Connect-SPOService: The type initializer for 'Microsoft.Win32.Registry' threw an exception.

 

 

Powershell Mac connection attempt.png

Well of course. There is no Win32.Registry on my Mac. Seems like there are still dependencies to Windows machines left.

 

@WhiteHotaru and @Bikash Maharjan On trying to use PowerShell from MacOSX:

 

My experience: PowerShell Core works on OSX in the sense that the software runs and that you can use a few modules, like Teams. Butyou simply cannot do anything 'serious' with PowerShell Core on a Mac. Too many modules (while they do install) simply do not work from Mac OSX, for the reason that @WhiteHotaru  mentioned. Even while many "e-learning books" claim that functionalities work with the PowerShell Core from a Mac (even documented with screenshots): they do not work. I talked to many people, and contacted a famous PnP programmer, they clearly stated that a lot if not most modules will not work from a Mac. 

 

My advise, if you are Mac user with a need/wish to work with Powershell:

- Use Bootcamp on your Mac to set up a lean Window partition; so you will get a truly native Windows installation); switching between OSX and WIN10 required a restart, but that takes a little of your time, like 10 seconds.

- download a Windows 10 installation from Microsoft. You are allowed to use it for a while without activation of the licence; at the end I preferred activating the licence, Windows 10 is worth its money (while I maintain convinced that MacOS is the better OS).

- then install the Windows PowerShell on your Windows  account (running natively on your Mac). Install Windows PowerShell 5.1;  the version where you see so many blogs and docs advising NOT to use it. But the point is, this Powershell version does everything you expect, it has a nice, very user-friendly interface as well. Use any of your OneDrive accounts to store scripts, so you can also look at them from your OSX environment.

- also install Visual Studio Code as well (you can also do this on your Mac, but ... without the Cmdlets not working, you would do that is you want to use other features, like help with your JSON code).

Succes!!!

@Bernd_Kroon I tested again and at least the Combination Powershell 7 and the modern PnP.Powershell Module work successfully with the device login option when logging in. SharePoint Online management shell is still broken.

@Bikash Maharjan years later and still having the issue.

@Bikash Maharjan 

 

I came across your post and, sadly, it is still behaving the same way over 2-years later, and throwing the same exception i.e.,

 

Connect-SPOService: The type initializer for 'Microsoft.Win32.Registry' threw an exception

@Bikash Maharjan 

 

on the back of this issue I engaged with Microsoft on the Github for the page and they have updated the page to explicitly mention that SharePoint Online PowerShell scripts only work with Windows PowerShell, i.e. the version of PowerShell that comes with Windows and is based on .NET 4.x.

 

If you want you can view the updated content on this here Intro to SharePoint Online Management Shell 

 

I hope this helps to solve the mystery and highlights that not all PowerShell Modules are created equal.  A shame really but hopefully future editions of PowerShell Core will support functionality to manage Azure and Microsoft 365.

 

 

This Module requires NuGet provider to run - not sure that's possible with MacOSX

@GuyThompsonDC 

 

Hi Guy,

your right, while it was torturous getting to the answer the Microsoft product team explained that this module requires Windows PowerShell so it will not work with PowerShell Core and its successors.

I have seen a list of Windows PowerShell apps that being made compatible with PowerShell Core, etc.

 

PowerShell 7 module compatibility more details are here, and herePowerShell differences on non-Windows platforms