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] Add set site version policy commands #3373

Merged

Conversation

msjennywu
Copy link
Contributor

@msjennywu msjennywu commented Aug 28, 2023

Before creating a pull request, make sure that you have read the contribution file located at

https://github.com/pnp/powerShell/blob/dev/CONTRIBUTING.md

Type

  • Bug Fix
  • New Feature
  • Sample

What is in this Pull Request ?

Add changes to let the Set-PnPSite supports to set version policy on site level.

Valid scenarios

Set-PnPSite -EnableAutoExpirationVersionTrim $true
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 101 -ExpireVersionsAfterDays 201
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 300 -ExpireVersionsAfterDays 0
Set-PnPSite -InheritTenantVersionPolicySettings
Set-PnPSite -EnableAutoExpirationVersionTrim $true -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 102 -MinorVersions 52 -ExpireVersionsAfterDays 202 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 300 -MinorVersions 70 -ExpireVersionsAfterDays 0 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs

Invalid scenarios

--The VersionPolicy related parameters (EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersions, MinorVersions StartApplyVersionPolicySettingToExistingDocLibs, CancelApplyVersionPolicySettingToExistingDocLibs) cannot be set when InheritTenantVersionPolicySettings is specified.
Set-PnPSite -InheritTenantVersionPolicySettings -EnableAutoExpirationVersionTrim $true
Set-PnPSite -InheritTenantVersionPolicySettings -MajorVersions 100
Set-PnPSite -InheritTenantVersionPolicySettings -MinorVersions 50
Set-PnPSite -InheritTenantVersionPolicySettings -ExpireVersionsAfterDays 100
Set-PnPSite -InheritTenantVersionPolicySettings -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -InheritTenantVersionPolicySettings -CancelApplyVersionPolicySettingToExistingDocLibs

--The VersionPolicy related parameters (EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersions, MinorVersions) cannot be set when CancelApplyVersionPolicySettingToExistingDocLibs is specified.
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs -EnableAutoExpirationVersionTrim $true
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs -MajorVersions 100
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs -MinorVersions 100
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs -ExpireVersionsAfterDays 100

--Don't specify both StartApplyVersionPolicySettingToExistingDocLibs and CancelApplyVersionPolicySettingToExistingDocLibs.
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs -StartApplyVersionPolicySettingToExistingDocLibs

--You must specify EnableAutoExpirationVersionTrim when StartApplyVersionPolicySettingToExistingDocLibs is specified
Set-PnPSite -StartApplyVersionPolicySettingToExistingDocLibs

--You must specify ExpireVersionsAfterDays, MajorVersions and MinorVersions when EnableAutoExpirationVersionTrim is false.
Set-PnPSite -EnableAutoExpirationVersionTrim $false -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MinorVersions 200 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 200 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 300 -MinorVersions 70 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 300 -ExpireVersionsAfterDays 0 -StartApplyVersionPolicySettingToExistingDocLibs
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MinorVersions 70 -ExpireVersionsAfterDays 0 -StartApplyVersionPolicySettingToExistingDocLibs

--Don't specify both ExpireVersionsAfterDays and MajorVersions when EnableAutoExpirationVersionTrim is true.
Set-PnPSite -EnableAutoExpirationVersionTrim $true -MajorVersions 100
Set-PnPSite -EnableAutoExpirationVersionTrim $true -ExpireVersionsAfterDays 200
Set-PnPSite -EnableAutoExpirationVersionTrim $true -MajorVersions 100 -ExpireVersionsAfterDays 200

--You must specify both ExpireVersionsAfterDays and MajorVersions when EnableAutoExpirationVersionTrim is false.
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100
Set-PnPSite -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 200

--Don't specify MinorVersions when StartApplyVersionPolicySettingToExistingDocLibs is not specified.
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -MinorVersions 40 -ExpireVersionsAfterDays 200
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MinorVersions 40 -ExpireVersionsAfterDays 200
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -MinorVersions 40

@msjennywu
Copy link
Contributor Author

msjennywu commented Aug 28, 2023

Build failed but not caused by my change. For example, the error message "'Tenant' does not contain a definition for 'DisableListSync' and no accessible extension method 'DisableListSync' accepting a first argument of type 'Tenant' could be found" is because DisableListSync is removed in sharepoint code.
@KoenZomers Do you know anyone will fix the issue in PnP powershell? And also please help to review the change. Thanks so much!

@KoenZomers KoenZomers force-pushed the SPFileVersionSiteVersionPolicyCommands branch from e56487b to 24573e9 Compare September 2, 2023 21:31
@KoenZomers
Copy link
Collaborator

@msjennywu Build error was caused by two properties having been removed from the latest SharePoint CSOM libraries. We automatically import the latest version. That has been fixed now and your PR builds again. I trust you have tested it properly. From a high glance it looks good, so will continue with merging.

@KoenZomers KoenZomers force-pushed the SPFileVersionSiteVersionPolicyCommands branch from 24573e9 to ec28945 Compare September 2, 2023 21:42
@KoenZomers KoenZomers merged commit 3f10dc9 into pnp:dev Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants