Using Powershell is there a way to find if a SharePoint Online site has a retention policy applied to it.

Paul Wright 5 Reputation points
2024-04-22T14:15:57.3933333+00:00

I am working on an automation and have found the option to exclude a SharePoint site from a compliance retention policy

What I am looking for is to create a loop to check if the site has had the retention policy removed. So really just a cmdlet that checks the site for retention. This of course can be done manually using the Purview's lookup in the GUI. I cannot find any cmldet to interrogate the site for this information. So just to be clear I don;t require the name of the policy, but just to check whether the SP site is under retention or not.

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Purview
{count} votes

2 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2024-04-23T06:55:12.4666667+00:00

    Hi @Paul Wright,

    Thank you for posting in this community.

    First, please install PnP module first:

    Install the PnP PowerShell Module for SharePoint Online.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    You can use this PowerShell to get the policies used by site:

    # Connect to your SharePoint Online site
    Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite"
    
    # Get the policies applied to the site collection
    Get-PnPSitePolicy 
    

    Reference: Get-PnPSitePolicy.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Bhargava-MSFT 31,261 Reputation points Microsoft Employee Moderator
    2024-04-23T17:46:27.76+00:00

    Hi Paul,

    Thanks for the details.

    I see from the below documents, you can use "Connect-IPPSSession" to connect to Security and Compliance powershell

    Get-RetentionCompliancePolicy cmdlet to view existing retention policies in the Microsoft Purview compliance portal.

    https://learn.microsoft.com/en-us/powershell/module/exchange/get-retentioncompliancepolicy?view=exchange-ps

    https://learn.microsoft.com/en-us/powershell/module/exchange/connect-ippssession?view=exchange-ps

    I hope this helps.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.