Fix Add-PnPGroupMember Adding Users to the Wrong SharePoint Group
Question details
Users are being added to a SharePoint group with a duplicate name on another site when executing the Add-PnPGroupMember PowerShell command.

- 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.
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.
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.
Before running the add command, establish a fresh connection to the specific site using the command Connect-PnPOnline -Url <YourTargetSiteURL>.
Execute Get-PnPContext to guarantee that your active PowerShell session is definitively tied to the correct SharePoint site.
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.
Run Add-PnPGroupMember -LoginName <UserEmail> -Group <GroupID> to explicitly add the user to the correct group without naming conflicts.

Escalate to Microsoft Online Support
If managing the PowerShell connection context fails to resolve the issue, backend tenant misconfigurations or caching errors may require administrative investigation.
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. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the installer and follow the simple on-screen instructions to set up the software in minutes.
- 3. Open and Edit: Launch WPS Office and instantly open your existing Microsoft Office files to resume your work without losing any formatting.

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.




