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

 

 

2 Replies

  • The error indicates that SharePoint Online is not resolving the user principal passed to Add-SPOUser. This usually happens when the LoginName format is incorrect or when the account does not yet exist in the site collection’s user cache.

    Try the following:

    • Use the UPN format instead of the mailto: format. For example:
      -LoginName email address removed for privacy reasons
    • Make sure the user has accessed the site at least once or add the user to the site collection using:
      Set-SPOUser -Site <site> -LoginName email address removed for privacy reasons -IsSiteCollectionAdmin $false
      This ensures the user exists in the site’s user info list.
    • PnP PowerShell can add users more reliably, but the standard SPO module works as long as the LoginName is resolved correctly.

    The “Unknown Error” typically means the user lookup failed, not that the cmdlet is broken.

  • 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