Skip to content
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

Improves Set-PnPMicrosoft365Group to provide option to update MailNickname #3529

Merged
merged 11 commits into from
Nov 7, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner`, `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory`, `New-PnPAzureADUserTemporaryAccessPass` and `Get-PnPAvailableSensitivityLabel` cmdlets. [#3484](https://github.com/pnp/powershell/pull/3484)
- Added a devcontainer for easily building a minimal environment necessary to contribute to the project. [#3497](https://github.com/pnp/powershell/pull/3497)
- Added `-RelativeUrl` parameter to `Connect-PnPOnline` cmdlet to allow specifying custom URLs for usage with `-WebLogin` method. [#3530](https://github.com/pnp/powershell/pull/3530)
- Added `-MailNickname` parameter to `Set-PnPMicrosoft365Group` cmdlet to allow changing of this property on a Microsoft 365 Group [#3529](https://github.com/pnp/powershell/pull/3529)

### Fixed

Expand Down
16 changes: 15 additions & 1 deletion documentation/Set-PnPMicrosoft365Group.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Sets Microsoft 365 Group properties
```powershell
Set-PnPMicrosoft365Group -Identity <Microsoft365GroupPipeBind> [-DisplayName <String>] [-Description <String>]
[-Owners <String[]>] [-Members <String[]>] [-IsPrivate] [-LogoPath <String>] [-CreateTeam]
[-HideFromAddressLists <Boolean>] [-HideFromOutlookClients <Boolean>] [-SensitivityLabels <GUID[]>]
[-HideFromAddressLists <Boolean>] [-HideFromOutlookClients <Boolean>] [-MailNickname <String>] [-SensitivityLabels <GUID[]>]

```

Expand Down Expand Up @@ -160,6 +160,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -MailNickname
The mail alias for the group, unique for Microsoft 365 groups in the organization. Maximum length is 64 characters. This property can contain only characters in the ASCII character set 0 - 127 except the following: @ () \ [] " ; : . <> , SPACE

```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Identity
The Identity of the Microsoft 365 Group

Expand Down
15 changes: 15 additions & 0 deletions src/Commands/Microsoft365Groups/SetMicrosoft365Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class SetMicrosoft365Group : PnPGraphCmdlet
[Parameter(Mandatory = false)]
public Guid[] SensitivityLabels;

[Parameter(Mandatory = false)]
public string MailNickname;

protected override void ExecuteCmdlet()
{
var group = Identity.GetGroup(Connection, AccessToken, false, false);
Expand All @@ -74,6 +77,18 @@ protected override void ExecuteCmdlet()
group.Visibility = IsPrivate ? "Private" : "Public";
changed = true;
}
if (ParameterSpecified(nameof(MailNickname)))
{
//Ensures mailNickname contain only characters in the ASCII character set 0 - 127 except the following: @ () \ [] " ; : . <> , SPACE.
MailNickname = MailNickname.Replace("@", "").Replace("(", "").Replace(")", "").Replace("\\", "").Replace("[", "").Replace("]", "").Replace("\"", "").Replace(";", "").Replace(":", "").Replace(".", "").Replace("<", "").Replace(">", "").Replace(",", "").Replace(" ", "");
// Ensures Maximum length is 64 characters.
if (MailNickname.Length > 64)
{
MailNickname = MailNickname.Substring(0, 64);
}
group.MailNickname = MailNickname;
changed = true;
}
if (changed)
{
group = Microsoft365GroupsUtility.UpdateAsync(Connection, AccessToken, group).GetAwaiter().GetResult();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ internal static async Task<Microsoft365Group> UpdateAsync(PnPConnection connecti
{
return await GraphHelper.PatchAsync(connection, accessToken, $"v1.0/groups/{group.Id}", group);
}

internal static async Task SetVisibilityAsync(PnPConnection connection, string accessToken, Guid groupId, bool? hideFromAddressLists, bool? hideFromOutlookClients)
{
var patchData = new
Expand Down
Loading