Skip to content

Commit f2fe362

Browse files
authored
Merge pull request #2869 from msjennywu/SPFileVersion
Support document library owner to make change of the file version trim mode
2 parents 344fbe3 + 05d72c0 commit f2fe362

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5858
- Added `-Identity` option to `Get-PnPPowerPlatformEnvironment` which allows retrieval of one specific environment by its displayname or id. [#2794](https://github.com/pnp/powershell/pull/2794)
5959
- Added `Get-PnPPowerApp` which allows PowerApps to be retrieved [#2794](https://github.com/pnp/powershell/pull/2794)
6060
- Added `-DisableCommenting` to `Set-PnPList` which allows enabling or disabling commenting on a list. [#2939](https://github.com/pnp/powershell/pull/2939)
61+
- Added `-EnableAutoExpirationVersionTrim` and `-ExpireVersionsAfterDays` to `Set-PnPList` which allows enabling or disabling auto expiration of versions on a list or library based on the days passed. [#2869](https://github.com/pnp/powershell/pull/2869)
6162

6263
### Changed
6364

@@ -108,6 +109,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
108109
- Fixed `Add-PnPFieldFromXml` cmdlet. It will now return the correct typed field if the added field was of type `Taxonomy`. [#2926](https://github.com/pnp/powershell/pull/2926)
109110

110111
### Contributors
112+
113+
- [msjennywu]
111114
- [enthusol]
112115
- Ganesh Sanap [ganesh-sanap]
113116
- Chris R. [ChrisRo89]

documentation/Set-PnPList.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Set-PnPList -Identity <ListPipeBind> [-EnableContentTypes <Boolean>] [-BreakRole
2121
[-EnableAttachments <Boolean>] [-EnableFolderCreation <Boolean>] [-EnableVersioning <Boolean>]
2222
[-EnableMinorVersions <Boolean>] [-MajorVersions <UInt32>] [-MinorVersions <UInt32>]
2323
[-EnableModeration <Boolean>] [-DraftVersionVisibility <DraftVisibilityType>] [-ReadSecurity <ListReadSecurity>] [-WriteSecurity <ListWriteSecurity>]
24-
[-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles <Boolean>] [-DisableGridEditing <Boolean>] [-DisableCommenting <Boolean>] [-DefaultSensitivityLabelForLibrary <SensitivityLabelPipeBind>]
25-
[-Path <String>] [-OpenDocumentsMode <DocumentLibraryOpenDocumentsInMode>] [-Connection <PnPConnection>]
24+
[-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles <Boolean>] [-DisableGridEditing <Boolean>] [-DisableCommenting <Boolean>]
25+
[-EnableAutoExpirationVersionTrim <Boolean>] [-ExpireVersionsAfterDays <UInt32>]
26+
[-DefaultSensitivityLabelForLibrary <SensitivityLabelPipeBind>] [-Path <String>] [-OpenDocumentsMode <DocumentLibraryOpenDocumentsInMode>] [-Connection <PnPConnection>]
2627
```
2728

2829
## DESCRIPTION
@@ -81,6 +82,27 @@ Rename a list, including its' URL.
8182

8283
### EXAMPLE 8
8384
```powershell
85+
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $true
86+
```
87+
88+
Enable AutoExpiration file version trim mode on a doccument library.
89+
90+
### EXAMPLE 9
91+
```powershell
92+
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 30 -MajorVerions 500
93+
```
94+
95+
Enable ExpireAfter file version trim mode on a doccument library. MinorVersions is also needed when minor version is enabled.
96+
97+
### EXAMPLE 10
98+
```powershell
99+
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 0 -MajorVerions 500
100+
```
101+
102+
Enable NoExpiration file version trim mode on a doccument library. MinorVersions is also needed when minor version is enabled.
103+
104+
### EXAMPLE 11
105+
```powershell
84106
Set-PnPList -Identity "Demo List" -DefaultSensitivityLabelForLibrary "Confidential"
85107
```
86108

@@ -496,6 +518,38 @@ Accept pipeline input: False
496518
Accept wildcard characters: False
497519
```
498520
521+
### -EnableAutoExpirationVersionTrim
522+
Enable or disable AutoExpiration version trim for the document library. Set to $true to enable, $false to disable.
523+
524+
Parameter ExpireVersionsAfterDays is required when EnableAutoExpirationVersionTrim is false. Set ExpireVersionsAfterDays to 0 for NoExpiration, set it to greater or equal 30 for ExpireAfter.
525+
526+
Parameter MajorVersions is required when EnableAutoExpirationVersionTrim is false.
527+
Parameter MinorVersions is required when EnableAutoExpirationVersionTrim is false and minor version is enabled.
528+
529+
```yaml
530+
Type: Boolean
531+
Parameter Sets: (All)
532+
533+
Required: False
534+
Position: Named
535+
Default value: None
536+
Accept pipeline input: False
537+
Accept wildcard characters: False
538+
```
539+
540+
### -ExpireVersionsAfterDays
541+
Work with parameter EnableAutoExpirationVersionTrim. Please see description in EnableAutoExpirationVersionTrim.
542+
543+
```yaml
544+
Type: UInt32
545+
Parameter Sets: (All)
546+
547+
Required: False
548+
Position: Named
549+
Default value: None
550+
Accept pipeline input: False
551+
Accept wildcard characters: False
552+
```
499553
## RELATED LINKS
500554
501-
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
555+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

src/Commands/Lists/SetList.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ public class SetList : PnPWebCmdlet
9090
public string Path;
9191

9292
[Parameter(Mandatory = false)]
93-
public SensitivityLabelPipeBind DefaultSensitivityLabelForLibrary;
93+
public bool EnableAutoExpirationVersionTrim;
94+
95+
[Parameter(Mandatory = false)]
96+
public int ExpireVersionsAfterDays;
97+
98+
[Parameter(Mandatory = false)]
99+
public SensitivityLabelPipeBind DefaultSensitivityLabelForLibrary;
94100

95101
[Parameter(Mandatory = false)]
96102
public DocumentLibraryOpenDocumentsInMode OpenDocumentsMode;
@@ -255,14 +261,72 @@ protected override void ExecuteCmdlet()
255261
// Is this for a list or a document library
256262
if (list.BaseType == BaseType.DocumentLibrary)
257263
{
264+
list.EnsureProperties(l => l.VersionPolicies);
265+
266+
if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)))
267+
{
268+
if (EnableAutoExpirationVersionTrim)
269+
{
270+
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.AutoExpiration;
271+
}
272+
else
273+
{
274+
if (!ParameterSpecified(nameof(MajorVersions)) || !ParameterSpecified(nameof(ExpireVersionsAfterDays)))
275+
{
276+
throw new PSArgumentException($"You must specify a value for {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersions)}", nameof(ExpireVersionsAfterDays));
277+
}
278+
279+
if (!ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
280+
{
281+
throw new PSArgumentException($"You must specify a value for {nameof(MinorVersions)} if it is enabled.", nameof(MinorVersions));
282+
}
283+
284+
if (ExpireVersionsAfterDays == 0)
285+
{
286+
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.NoExpiration;
287+
}
288+
else if (ExpireVersionsAfterDays >= 30)
289+
{
290+
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.ExpireAfter;
291+
}
292+
else
293+
{
294+
throw new PSArgumentException($"You must specify {nameof(ExpireVersionsAfterDays)} to be 0 for NoExpiration or greater equal 30 for ExpireAfter.", nameof(ExpireVersionsAfterDays));
295+
}
296+
}
297+
298+
updateRequired = true;
299+
}
300+
301+
if (ParameterSpecified(nameof(ExpireVersionsAfterDays)) && (int)ExpireVersionsAfterDays >= 30)
302+
{
303+
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
304+
{
305+
throw new PSArgumentException($"The parameter {nameof(ExpireVersionsAfterDays)} can't be set when AutoExpiration is enabled");
306+
}
307+
308+
list.VersionPolicies.DefaultExpireAfterDays = (int)ExpireVersionsAfterDays;
309+
updateRequired = true;
310+
}
311+
258312
if (ParameterSpecified(nameof(MajorVersions)))
259313
{
314+
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
315+
{
316+
throw new PSArgumentException($"The parameter {nameof(MajorVersions)} can't be set when AutoExpiration is enabled", nameof(MajorVersions));
317+
}
318+
260319
list.MajorVersionLimit = (int)MajorVersions;
261320
updateRequired = true;
262321
}
263322

264323
if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
265324
{
325+
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
326+
{
327+
throw new PSArgumentException($"The parameter {nameof(MinorVersions)} can't be set when AutoExpiration is enabled", nameof(MinorVersions));
328+
}
329+
266330
list.MajorWithMinorVersionsLimit = (int)MinorVersions;
267331
updateRequired = true;
268332
}

0 commit comments

Comments
 (0)