Forum Discussion

JasonYeung's avatar
JasonYeung
Brass Contributor
Dec 02, 2025

add user to SharePoint group via PowerShell error

Hi, 

I'm trying to use PowerShell to add a user to an existing SharePoint group. I ran the following to connect to the SharePoint site:

Connect-SPOService -Url https://site1-admin.sharepoint.com

This prompts me to login, password and MFA code. Afterwards I type in the following to add a user:

Add-SPOUser -Site https://site1-admin.sharepoint.com/sites/company -Group "Company Info Members" -LoginName mailto:email address removed for privacy reasons

There is a SharePoint group with the name "Company Info Members", which I want to add mailto:email address removed for privacy reasons to. But I get the following error:

Add-SPOUser : Unknown Error
At line:1 char:1
+ Add-SPOUser -Site https://site1-admin.sharepoint.com/s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-SPOUser], ServerException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.AddSP
   OUser

 

I was wondering what could be causing this error. I searched for the error on Copilot and it suggested I use "PnP.PowerShell". But I'm having some issues installing this app. I was wondering if there are any suggestions I could do? Thanks!

Jason

 

 

1 Reply

  • This error usually isn’t very helpful because “Unknown Error” is generic, but there are a couple of common issues in your command. First, the -Site URL should be the actual site URL, not the admin URL. So instead of https://site1-admin.sharepoint.com/sites/company, try https://site1.sharepoint.com/sites/company. Second, in -LoginName don’t include mailto: it should just be the UPN/email address, for example: Add-SPOUser -Site https://site1.sharepoint.com/sites/company -Group "Company Info Members" -LoginName email address removed for privacy reasons
    Also make sure that the user actually exists in your tenant (licensed or at least created) and that you’re a site collection admin on that site. PnP.PowerShell is great, but you don’t need it for this basic scenario—fixing the URL and login name is usually enough to get past this error.

    ------------------------------------
    Don't forget to mark as solution if my answer suits you

Resources