diff --git a/CHANGELOG.md b/CHANGELOG.md index ae69c24ed..05f458d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/documentation/Get-PnPSiteVersionPolicy.md b/documentation/Get-PnPSiteVersionPolicy.md new file mode 100644 index 000000000..994a84836 --- /dev/null +++ b/documentation/Get-PnPSiteVersionPolicy.md @@ -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 ] +``` + +## 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) \ No newline at end of file diff --git a/src/Commands/Model/SharePoint/SiteVersionPolicy.cs b/src/Commands/Model/SharePoint/SiteVersionPolicy.cs new file mode 100644 index 000000000..8f1659ec6 --- /dev/null +++ b/src/Commands/Model/SharePoint/SiteVersionPolicy.cs @@ -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 +{ + /// + /// 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. + /// + public class SiteVersionPolicy + { + /// + /// Site Url + /// + public string Url { get; set; } + + /// + /// Site DefaultTrimMode + /// e.g. AutoExpiration, ExpireAfter, NoExpiration + /// + public string DefaultTrimMode { get; set; } + + /// + /// Site DefaultExpireAfterDays + /// + public string DefaultExpireAfterDays { get; set; } + + /// + /// Site MajorVersionLimit + /// + public string MajorVersionLimit { get; set; } + + /// + /// Results description + /// + public string Description { get; set; } + } +} diff --git a/src/Commands/Site/GetSiteVersionPolicy.cs b/src/Commands/Site/GetSiteVersionPolicy.cs new file mode 100644 index 000000000..a1f676293 --- /dev/null +++ b/src/Commands/Site/GetSiteVersionPolicy.cs @@ -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); + } + } +}