Permission & Access Issues

Fix Add-PnPGroupMember Adding Users to the Wrong SharePoint Group

Kushani NimanthikaKushani Nimanthika Oct 14, 2026 870 views

Question details

Users are being added to a SharePoint group with a duplicate name on another site when executing the Add-PnPGroupMember PowerShell command.

Fix Add-PnPGroupMember Adding Users to the Wrong SharePoint Group
Product
SharePoint
Device & OS
not provided
Scenario
Running PnP PowerShell scripts to automate user assignment to specific SharePoint groups across different sites.
Observed behavior
The command assigns the user to an identically named group on a different SharePoint site instead of the intended target group.
Before you start

Ensure you have the latest version of the PnP PowerShell module installed and hold the necessary SharePoint administrator or site owner permissions for the target site before running scripts.

Solution 1Recommended

Specify the Exact Site Context and Group ID

Connecting to the exact site URL and targeting groups by their unique ID prevents the command from defaulting to duplicate group names across the tenant.

When managing multiple SharePoint sites, relying on group names can cause conflicts if the same name is used across different sites. Explicitly defining the site context and using unique numeric identifiers ensures accuracy.

1
Connect to the Target Site

Before running the add command, establish a fresh connection to the specific site using the command Connect-PnPOnline -Url <YourTargetSiteURL>.

2
Verify the Web Context

Execute Get-PnPContext to guarantee that your active PowerShell session is definitively tied to the correct SharePoint site.

3
Retrieve the Specific Group ID

Instead of using the group's display name, run Get-PnPGroup on the target site to locate the unique numeric ID of the intended group.

4
Execute the Add Command

Run Add-PnPGroupMember -LoginName <UserEmail> -Group <GroupID> to explicitly add the user to the correct group without naming conflicts.

Specify the Exact Site Context and Group ID
Context Matters: Testing your script against one site at a time and manually verifying the context can prevent widespread permission errors in automated scripts.
Free Microsoft Office alternative

Simplify Your Workflow with WPS Office

While troubleshooting backend Microsoft 365 issues and SharePoint PowerShell scripts can be highly complex, managing your daily documents should not be. WPS Office provides a lightweight, highly compatible, and completely free alternative to Microsoft Office, allowing you to edit and manage documents seamlessly without the hefty subscription costs.

  1. 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the installer and follow the simple on-screen instructions to set up the software in minutes.
  3. 3. Open and Edit: Launch WPS Office and instantly open your existing Microsoft Office files to resume your work without losing any formatting.
Fully compatible with Microsoft Office formats, including DOCX, XLSX, and PPTX.Lightweight installation with incredibly fast startup times.Familiar tabbed user interface, requiring zero learning curve to master.Powerful built-in PDF editing, conversion, and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Add-PnPGroupMember target the wrong SharePoint site?

This typically occurs if the active PowerShell connection context is still tied to a previously connected site, or if multiple sites share the exact same group name and the command defaults to an earlier cached context instead of the new site.

How can I ensure my script disconnects from previous SharePoint sites?

Use the Disconnect-PnPOnline command before initiating a new connection with Connect-PnPOnline to clear previous contexts and guarantee a clean state for the next site's commands.

Is it better to use a Group ID instead of a Group Name in PnP PowerShell?

Yes. Using a Group ID is highly recommended because it is universally unique within the specific site collection. This prevents accidental assignment to duplicate group names that might exist on other sites within the same tenant.