Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileVersion] Get-PnPSite change for VersionPolicy #3470

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added option to pass in a Stream or XML string to `Read-PnPTenantTemplate` allowing the tenant template to be modified before being applied. [#3431](https://github.com/pnp/powershell/pull/3431)
- Added `Get-PnPTenantInfo` which allows retrieving tenant information by its Id or domain name. [#3414](https://github.com/pnp/powershell/pull/3414)
- Added option to create a Microsoft 365 Group with dynamic membership by passing in `-DynamicMembershipRule` [#3426](https://github.com/pnp/powershell/pull/3426)
- Added `Get-PnPSiteVersionPolicy` which allows retrieval of the version policy settings for a site [#3470](https://github.com/pnp/powershell/pull/3470)
- Added `RestrictedAccessControl`, `ClearRestrictedAccessControl`, `RemoveRestrictedAccessControlGroups`, `AddRestrictedAccessControlGroups` and `RestrictedAccessControlGroups` parameters to `Set-PnPTenantSite` cmdlet to handle restricted access control. [#3463](https://github.com/pnp/powershell/pull/3463)
- Added `Get-PnPRetentionLabel` cmdlet to retrieve Purview retention labels. [#3459](https://github.com/pnp/powershell/pull/3459)
- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner`, `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory`, `New-PnPAzureADUserTemporaryAccessPass` and `Get-PnPAvailableSensitivityLabel` cmdlets. [#3484](https://github.com/pnp/powershell/pull/3484)
Expand Down
53 changes: 53 additions & 0 deletions documentation/Get-PnPSiteVersionPolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPSiteVersionPolicy.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPSiteVersionPolicy
---

# Get-PnPSiteVersionPolicy

## SYNOPSIS
Get version policy setting of the site.

## SYNTAX

```powershell
Get-PnPSiteVersionPolicy [-Connection <PnPConnection>]
```

## DESCRIPTION
This cmdlet allows retrieval of version policy setting on the site. When the new document libraries are created, they will be set as the version policy of the site.
If the version policy is not set on the site, the setting of the tenant will be used.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPSiteVersionPolicy
```

Returns the version policy setting of the site.

## PARAMETERS

### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft Docs documentation](https://learn.microsoft.com/sharepoint/dev/solution-guidance/modern-experience-site-classification#programmatically-read-the-classification-of-a-site)
42 changes: 42 additions & 0 deletions src/Commands/Model/SharePoint/SiteVersionPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PnP.PowerShell.Commands.Model.SharePoint
{
/// <summary>
/// The VersionPolicy setting on site
/// When the new document libraries are created, they will be set as the version policy of the site.
/// If the version policy is not set on the site, the setting on the tenant will be used.
/// </summary>
public class SiteVersionPolicy
{
/// <summary>
/// Site Url
/// </summary>
public string Url { get; set; }

/// <summary>
/// Site DefaultTrimMode
/// e.g. AutoExpiration, ExpireAfter, NoExpiration
/// </summary>
public string DefaultTrimMode { get; set; }

/// <summary>
/// Site DefaultExpireAfterDays
/// </summary>
public string DefaultExpireAfterDays { get; set; }

/// <summary>
/// Site MajorVersionLimit
/// </summary>
public string MajorVersionLimit { get; set; }

/// <summary>
/// Results description
/// </summary>
public string Description { get; set; }
}
}
55 changes: 55 additions & 0 deletions src/Commands/Site/GetSiteVersionPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.SharePoint.Client;

using System;
using System.Linq.Expressions;
using System.Management.Automation;
using PnP.PowerShell.Commands.Model.SharePoint;

namespace PnP.PowerShell.Commands.Site
{
[Cmdlet(VerbsCommon.Get, "PnPSiteVersionPolicy")]
[OutputType(typeof(PnP.PowerShell.Commands.Model.SharePoint.SiteVersionPolicy))]
public class GetSiteVersionPolicy : PnPSharePointCmdlet
{
protected override void ExecuteCmdlet()
{
ClientContext.Load(ClientContext.Site, s => s.Url, s => s.VersionPolicyForNewLibrariesTemplate, s => s.VersionPolicyForNewLibrariesTemplate.VersionPolicies);
ClientContext.ExecuteQueryRetry();
var site = ClientContext.Site;

var vp = new SiteVersionPolicy();
vp.Url = site.Url;

if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.ServerObjectIsNull == true)
{
vp.Description = "No Site Level Policy Set";
}
else
{
site.EnsureProperties(s => s.VersionPolicyForNewLibrariesTemplate, s => s.VersionPolicyForNewLibrariesTemplate.MajorVersionLimit, s => s.VersionPolicyForNewLibrariesTemplate.VersionPolicies);

vp.DefaultTrimMode = site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode.ToString();

if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
{
vp.Description = "Site has Automatic Policy Set";
}
else
{
if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.ExpireAfter)
{
vp.DefaultExpireAfterDays = site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultExpireAfterDays.ToString();
vp.Description = "Site has Manual settings with specific count and time limits";
}
else if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.NoExpiration)
{
vp.Description = "Site has Manual settings with specific version count limit and no time limits";
}
vp.MajorVersionLimit = site.VersionPolicyForNewLibrariesTemplate.MajorVersionLimit.ToString();
}
}

WriteObject(vp);
}
}
}