-
Notifications
You must be signed in to change notification settings - Fork 394
Add ClearGroupId parameter to Set-PnPSite and Set-PnPTenantSite cmdlets to remove assigned Microsoft 365 group ID #5192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ts to remove assigned Microsoft 365 group ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds a new ClearGroupId parameter to the Set-PnPSite and Set-PnPTenantSite cmdlets, enabling administrators to remove the assigned Microsoft 365 group ID from a SharePoint site when the associated group has been permanently deleted. This addresses issue #5189 by providing a way to clean up orphaned group references on sites.
Key changes:
- Added
ClearGroupIdSwitchParameter to both cmdlets to enable clearing of Microsoft 365 group ID associations - Updated documentation for both cmdlets to describe the new parameter and its purpose
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/Commands/Site/SetSite.cs | Adds ClearGroupId parameter declaration, implementation logic, and updates IsTenantProperty() method |
| src/Commands/Admin/SetTenantSite.cs | Adds ClearGroupId parameter declaration and implementation logic |
| documentation/Set-PnPSite.md | Documents the new ClearGroupId parameter in the syntax and parameters sections |
| documentation/Set-PnPTenantSite.md | Documents the new ClearGroupId parameter in the syntax and parameters sections |
src/Commands/Site/SetSite.cs
Outdated
| if (ClearGroupId.HasValue) | ||
| { | ||
| siteProperties.ClearGroupId = ClearGroupId.Value; | ||
| executeQueryRequired = true; | ||
| } |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of ClearGroupId in SetSite.cs is missing the ParameterSpecified check. The current code at line 464 only checks ClearGroupId.HasValue, but similar parameters like ReadOnlyForBlockDownloadPolicy (line 458) use both ParameterSpecified(nameof(ReadOnlyForBlockDownloadPolicy)) and .IsPresent. Without the ParameterSpecified check, the cmdlet may incorrectly process this parameter when it hasn't been explicitly provided by the user. The check should be: if (ParameterSpecified(nameof(ClearGroupId)) && ClearGroupId.HasValue)
src/Commands/Site/SetSite.cs
Outdated
| [Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)] | ||
| public SwitchParameter? ClearGroupId; |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClearGroupId parameter is declared as nullable SwitchParameter? in SetSite.cs, but the same parameter in SetTenantSite.cs (line 236) is declared as non-nullable SwitchParameter. For consistency and following the patterns used elsewhere in the codebase (e.g., ReadOnlyForBlockDownloadPolicy at line 141), this should be declared as non-nullable SwitchParameter and checked using ParameterSpecified in the implementation.
| ### -ClearGroupId | ||
| This parameter allows you to remove the assigned Microsoft 365 group ID on a site, when the group is permanently deleted. | ||
| ```yaml | ||
| Type: Switch Parameter | ||
| Parameter Sets: Set Properties | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for the ClearGroupId parameter should include a usage example in the EXAMPLES section showing how to use this parameter to remove the assigned Microsoft 365 group ID. This would help users understand the practical application of this new feature. Consider adding an example like: "Set-PnPSite -Identity https://contoso.sharepoint.com/sites/site1 -ClearGroupId" with a description explaining when and why this would be used (e.g., when the Microsoft 365 group has been permanently deleted).
| ### -ClearGroupId | ||
| This parameter allows you to remove the assigned Microsoft 365 group ID on a site, when the group is permanently deleted. | ||
|
|
||
| ```yaml | ||
| Type: Switch Parameter | ||
| Parameter Sets: Set Properties | ||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for the ClearGroupId parameter should include a usage example in the EXAMPLES section showing how to use this parameter to remove the assigned Microsoft 365 group ID. This would help users understand the practical application of this new feature. Consider adding an example like: "Set-PnPTenantSite -Identity https://contoso.sharepoint.com/sites/site1 -ClearGroupId" with a description explaining when and why this would be used (e.g., when the Microsoft 365 group has been permanently deleted).
src/Commands/Site/SetSite.cs
Outdated
| [Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)] | ||
| public SwitchParameter? ClearGroupId; |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the PnP PowerShell contribution guidelines, when proposing a code change in a PR, an entry should be added to the CHANGELOG.md file under the [Current nightly] section. This PR adds a new parameter (ClearGroupId) to Set-PnPSite and Set-PnPTenantSite cmdlets but doesn't include a CHANGELOG entry. Please add an entry under the "Added" section with a description like: "Added -ClearGroupId parameter to Set-PnPSite and Set-PnPTenantSite cmdlets to allow removing assigned Microsoft 365 group ID #5189" (replace XXXX with the actual PR number).
Type
Related Issues?
Fixes #5189
What is in this Pull Request ?
Add parameter ClearGroupId to set-pnpsite and tenantsite cmdlet