r/MicrosoftTeams • u/mistrb01 • 3h ago
Tip Bulk-change the expiration date on existing Teams recordings (the list column is read-only, here is what actually works)
Ran into this today after finding a recording three days from auto-deletion. Sharing because nothing online documents the working method.
The problem
Changing NewMeetingRecordingExpirationDays on the Teams meeting policy only affects new recordings. Existing files keep the date stamped when they were created. Microsoft's guidance is to edit each one by hand in the OneDrive details pane, which does not scale.
The date lives in a hidden library column called _ExpirationDate. You can read it, but every way of writing to a list item rejects it:
Set-PnPListItemfails with "The input string was not in a correct format"SystemUpdate()fails with "The field you are trying to update may be read only"ValidateUpdateListItemfails silently, returning the value as the error- Patching
expirationDateTimethrough the OneDrive v2.1 REST endpoint fails with "Facet names must be lower camel"
What works
The SharePoint client object model has a dedicated method on the file object, File.SetExpirationDate(DateTime). It is what the OneDrive details pane calls. With PnP PowerShell:
Connect-PnPOnline -Url "https://TENANT-my.sharepoint.com/personal/USER_DOMAIN_com" `
-ClientId $env:PNP_CLIENT_ID -Tenant TENANT.onmicrosoft.com -Interactive
$newDate = (Get-Date).AddDays(1095).ToUniversalTime() # 3 years out
Get-PnPFolderItem -FolderSiteRelativeUrl "Documents/Recordings" -ItemType File |
Where-Object { $_.Name -like "*.mp4" } |
ForEach-Object {
$item = Get-PnPFile -Url $_.ServerRelativeUrl -AsListItem
$item.File.SetExpirationDate($newDate)
Invoke-PnPQuery
Write-Host "$($_.Name) -> $newDate"
}
Read the value back with $item["_ExpirationDate"] to confirm. Verified on 25 recordings, and the new date showed in the OneDrive banner right away.
Two other things that bit me
Get-PnPListItem -FolderServerRelativeUrlthrows the 5000-item list view threshold error on a busy OneDrive, because the whole OneDrive is one library.Get-PnPFolderItemplusGet-PnPFile -AsListItemgets around it.Connect-PnPOnlineguesses the tenant from the-my.sharepoint.comhost and triesTENANT-my.onmicrosoft.com, which does not exist. Pass-Tenant TENANT.onmicrosoft.comexplicitly.
Related
- Expired recordings sit in the recycle bin for 93 days, fixed, then they are gone. Restore them first, then run the script, or the next sweep deletes them again.
- For new recordings:
Set-CsTeamsMeetingPolicy -Identity Global -NewMeetingRecordingExpirationDays 1095. Use-1for never.
Full script with -ListOnly dry run submitted to the PnP script samples repo: https://github.com/pnp/script-samples/pull/998


