Skip to content

Conversation

@gautamdsheth
Copy link
Collaborator

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #5189

What is in this Pull Request ?

Add parameter ClearGroupId to set-pnpsite and tenantsite cmdlet

…ts to remove assigned Microsoft 365 group ID
Copilot AI review requested due to automatic review settings December 16, 2025 19:25
Copy link
Contributor

Copilot AI left a 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 ClearGroupId SwitchParameter 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

Comment on lines 464 to 468
if (ClearGroupId.HasValue)
{
siteProperties.ClearGroupId = ClearGroupId.Value;
executeQueryRequired = true;
}
Copy link

Copilot AI Dec 16, 2025

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)

Copilot uses AI. Check for mistakes.
Comment on lines 143 to 144
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public SwitchParameter? ClearGroupId;
Copy link

Copilot AI Dec 16, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +697 to +709
### -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
```
Copy link

Copilot AI Dec 16, 2025

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).

Copilot uses AI. Check for mistakes.
Comment on lines +820 to +832
### -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
```
Copy link

Copilot AI Dec 16, 2025

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).

Copilot uses AI. Check for mistakes.
Comment on lines 143 to 144
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public SwitchParameter? ClearGroupId;
Copy link

Copilot AI Dec 16, 2025

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).

Copilot generated this review using guidance from repository custom instructions.
@gautamdsheth gautamdsheth merged commit fe8c789 into dev Dec 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add -ClearGroupId to Set-PnPSite

2 participants