Skip to content

Commit

Permalink
Merge pull request #760 from reshmee011/m365_renew
Browse files Browse the repository at this point in the history
new cmdlet to renew expiring m365 groups
  • Loading branch information
pkbullock authored Oct 27, 2024
2 parents d288782 + 6805c32 commit 51d2920
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
62 changes: 62 additions & 0 deletions scripts/aad-renew-m365-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
plugin: add-to-gallery
---

# Automate Renewal of Expiring M365 Groups or or Microsoft Teams teams

## Summary

It is a good practice to set lifecycle expiration policy to control sprawl. However that means that the group will get automatically deleted after they expire. The Teams/M365 groups owners will get email notifications to renew within a certain timeframe , however if the owners missed the renewal notifications for different reasons, it may lead to accidental data loss. The script can help identify M365 groups nearing expiration to renew them.

![Example Screenshot](assets/example.png)

# [PnP PowerShell](#tab/pnpps)

```powershell
param (
[Parameter(Mandatory = $true)]
[string] $domain
)
$adminSiteURL = "https://$domain-Admin.SharePoint.com"
$dateTime = "_{0:MM_dd_yy}_{0:HH_mm_ss}" -f (Get-Date)
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$fileName = "m365_group_expire_reset" + $dateTime + ".csv"
$outputPath = $directorypath + "\"+ $fileName
if (-not (Test-Path $outputPath)) {
New-Item -ItemType File -Path $outputPath
}
Connect-PnPOnline -Url $adminSiteURL -Interactive -WarningAction SilentlyContinue
Get-PnPMicrosoft365ExpiringGroup | ForEach-Object {
$group = $_
Reset-PnPMicrosoft365GroupExpiration -Identity $group.Id
$group = Get-PnPMicrosoft365Group -Identity $group.Id
$group | Select-Object id, RenewedDateTime,DisplayName|Export-Csv -Path $outputPath -NoTypeInformation -Append
}
Disconnect-PnPOnline
```
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

***

## Source Credit

Sample first appeared on [Automate Renewal of Expiring M365 Groups Using PowerShell](https://reshmeeauckloo.com/posts/powershell-renew-expiring-m365-group/)


## Contributors

| Author(s) |
|-----------|
| [Reshmee Auckloo](https://github.com/reshmee011) |


[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/aad-renew-m365-group" aria-hidden="true" />

Binary file added scripts/aad-renew-m365-group/assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions scripts/aad-renew-m365-group/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[
{
"name": "aad-renew-m365-group",
"source": "pnp",
"title": "Automate Renewal of Expiring M365 Groups or or Microsoft Teams teams",
"shortDescription": "Automate Renewal of Expiring M365 Groups or or Microsoft Teams teams",
"url": "https://pnp.github.io/script-samples/aad-renew-m365-group/README.html",
"longDescription": [
"Automate Renewal of Expiring M365 Groups or or Microsoft Teams teams"
],
"creationDateTime": "2024-10-27",
"updateDateTime": "2024-10-27",
"products": [
"SharePoint",
"Microsoft Teams",
"Microsoft 365 Group"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.99.0"
}
],
"categories": [
"Governance",
"Deploy",
"Provision"
],
"tags": [
"modern",
"Connect-PnPOnline",
"Disconnect-PnPOnline",
"Get-PnPMicrosoft365ExpiringGroup",
"Reset-PnPMicrosoft365GroupExpiration",
"Get-PnPMicrosoft365Group"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/aad-renew-m365-group/assets/example.png",
"alt": ""
}
],
"authors": [
{
"gitHubAccount": "reshmee011",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
"name": "Reshmee Auckloo"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]

0 comments on commit 51d2920

Please sign in to comment.