What it is
A destructive PowerShell sample that signs in interactively with MSAL.PS, lists every message in one Viva Engage community through the Yammer REST API, optionally backs them up to CSV, and then deletes them. Deletion can't be undone. The script header says it is intended for non-production environments, runs as a dry run by default ($whatIfMode = $true), and soft-deletes unless $hardDelete is set to $true, which permanently purges the messages.
Why use it
- Clear all content from a non-production community in one run.
- Preview what would be deleted first;
$whatIfModeis$trueby default. - Back up the messages to CSV before deleting, and choose soft delete (default) or permanent hard delete.
- Microsoft Graph has no API for community messages, so the Yammer REST API is the only option today.
How to use it
- Create a Microsoft Entra app registration with the delegated Yammer
access_as_userpermission and install the module withInstall-Module MSAL.PS. - Find the ID of the community to clear and set
$ClientId,$TenantId,$RedirectUri, and$GroupIdnear the top of the script. - Run with the default
$whatIfMode = $trueand review the output. Set it to$falseonly when you are sure. - Run:
.\Delete-AllCommunityPosts.ps1Prerequisites
- Test in a non-production tenant first; deletion can't be undone and hard delete is unrecoverable
- Microsoft Entra app registration with the delegated Yammer access_as_user permission
- MSAL.PS PowerShell module
- ID of the Viva Engage community to clear
- Viva Engage admin account