Scripts · PowerShell

Delete-AllCommunityPosts

Delete every message in a Viva Engage community; dry run by default, optional CSV backup, and deletion can't be undone.

View on GitHub

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; $whatIfMode is $true by 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

  1. Create a Microsoft Entra app registration with the delegated Yammer access_as_user permission and install the module with Install-Module MSAL.PS.
  2. Find the ID of the community to clear and set $ClientId, $TenantId, $RedirectUri, and $GroupId near the top of the script.
  3. Run with the default $whatIfMode = $true and review the output. Set it to $false only when you are sure.
  4. Run:
.\Delete-AllCommunityPosts.ps1

Prerequisites

  • 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