Skip to content
DnsLister Forum

Where domain hunters compare notes

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-PnPListItem fails with "The input string was not in a correct format"
  • SystemUpdate() fails with "The field you are trying to update may be read only"
  • ValidateUpdateListItem fails silently, returning the value as the error
  • Patching expirationDateTime through 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

  1. Get-PnPListItem -FolderServerRelativeUrl throws the 5000-item list view threshold error on a busy OneDrive, because the whole OneDrive is one library. Get-PnPFolderItem plus Get-PnPFile -AsListItem gets around it.
  2. Connect-PnPOnline guesses the tenant from the -my.sharepoint.com host and tries TENANT-my.onmicrosoft.com, which does not exist. Pass -Tenant TENANT.onmicrosoft.com explicitly.

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 -1 for never.

Full script with -ListOnly dry run submitted to the PnP script samples repo: https://github.com/pnp/script-samples/pull/998

Source: r/sharepoint · by /u/mistrb01

Leave a Reply

Your email address will not be published. Required fields are marked *