Configure / Deploy / Provision

Automate Renewal of Expiring M365 Groups or or Microsoft Teams teams

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

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

Source Credit

Sample first appeared on Automate Renewal of Expiring M365 Groups Using PowerShell

Contributors

Author(s)
Reshmee Auckloo

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Tool documentation & references

Keep exploring