Add FileTypesForVersionExpiration parameter to Set-PnPTenant cmdlet#5278
Add FileTypesForVersionExpiration parameter to Set-PnPTenant cmdlet#5278gautamdsheth merged 2 commits intodevfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for specifying file-type-specific version expiration overrides when running Set-PnPTenant.
Changes:
- Added a new
-FileTypesForVersionExpirationparameter to theSet-PnPTenantcmdlet implementation. - Added cmdlet logic to validate the parameter and invoke
Tenant.SetFileTypeVersionPolicy(...). - Updated
Set-PnPTenantdocumentation to include the new parameter and usage guidance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Commands/Admin/SetTenant.cs |
Introduces the new parameter and applies the file type version policy via CSOM. |
documentation/Set-PnPTenant.md |
Documents the new parameter in syntax and parameter reference. |
src/Commands/Admin/SetTenant.cs
Outdated
| if (!modified) | ||
| { | ||
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must be combined with {nameof(EnableAutoExpirationVersionTrim)} or with both {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersionLimit)}.", nameof(FileTypesForVersionExpiration)); | ||
| } |
There was a problem hiding this comment.
The validation for combining FileTypesForVersionExpiration with the version policy parameters relies on modified, but modified becomes true when any of ExpireVersionsAfterDays, MajorVersionLimit, or EnableAutoExpirationVersionTrim is provided (e.g., only MajorVersionLimit). This does not enforce the stated requirement of combining with EnableAutoExpirationVersionTrim OR with both ExpireVersionsAfterDays and MajorVersionLimit, and it can lead to calling SetFileTypeVersionPolicy with -1 values for missing parameters.
Consider replacing if (!modified) with an explicit check like EnableAutoExpirationVersionTrim.HasValue || (ExpireVersionsAfterDays.HasValue && MajorVersionLimit.HasValue) (and error if the requirement isn’t met).
src/Commands/Admin/SetTenant.cs
Outdated
| bool fileTypeVersionPolicyModified = false; | ||
| if (FileTypesForVersionExpiration != null) | ||
| { | ||
| if (FileTypesForVersionExpiration.Length == 0 || FileTypesForVersionExpiration.Any(string.IsNullOrWhiteSpace)) | ||
| { | ||
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must contain one or more non-empty file types.", nameof(FileTypesForVersionExpiration)); | ||
| } | ||
|
|
||
| FileTypesForVersionExpiration = FileTypesForVersionExpiration | ||
| .Distinct(StringComparer.OrdinalIgnoreCase) | ||
| .ToArray(); | ||
|
|
||
| if (!modified) | ||
| { | ||
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must be combined with {nameof(EnableAutoExpirationVersionTrim)} or with both {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersionLimit)}.", nameof(FileTypesForVersionExpiration)); | ||
| } | ||
|
|
||
| fileTypeVersionPolicyModified = true; | ||
| } |
There was a problem hiding this comment.
The newly added block uses tab indentation (\t) while the surrounding code in this method is indented with spaces. This introduces mixed whitespace in the same scope and can cause style/analyzer failures and noisy diffs.
Please re-indent this block to match the existing indentation used in the rest of ExecuteCmdlet() in this file.
| bool fileTypeVersionPolicyModified = false; | |
| if (FileTypesForVersionExpiration != null) | |
| { | |
| if (FileTypesForVersionExpiration.Length == 0 || FileTypesForVersionExpiration.Any(string.IsNullOrWhiteSpace)) | |
| { | |
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must contain one or more non-empty file types.", nameof(FileTypesForVersionExpiration)); | |
| } | |
| FileTypesForVersionExpiration = FileTypesForVersionExpiration | |
| .Distinct(StringComparer.OrdinalIgnoreCase) | |
| .ToArray(); | |
| if (!modified) | |
| { | |
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must be combined with {nameof(EnableAutoExpirationVersionTrim)} or with both {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersionLimit)}.", nameof(FileTypesForVersionExpiration)); | |
| } | |
| fileTypeVersionPolicyModified = true; | |
| } | |
| bool fileTypeVersionPolicyModified = false; | |
| if (FileTypesForVersionExpiration != null) | |
| { | |
| if (FileTypesForVersionExpiration.Length == 0 || FileTypesForVersionExpiration.Any(string.IsNullOrWhiteSpace)) | |
| { | |
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must contain one or more non-empty file types.", nameof(FileTypesForVersionExpiration)); | |
| } | |
| FileTypesForVersionExpiration = FileTypesForVersionExpiration | |
| .Distinct(StringComparer.OrdinalIgnoreCase) | |
| .ToArray(); | |
| if (!modified) | |
| { | |
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must be combined with {nameof(EnableAutoExpirationVersionTrim)} or with both {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersionLimit)}.", nameof(FileTypesForVersionExpiration)); | |
| } | |
| fileTypeVersionPolicyModified = true; | |
| } |
src/Commands/Admin/SetTenant.cs
Outdated
| if (FileTypesForVersionExpiration.Length == 0 || FileTypesForVersionExpiration.Any(string.IsNullOrWhiteSpace)) | ||
| { | ||
| throw new PSArgumentException($"The parameter {nameof(FileTypesForVersionExpiration)} must contain one or more non-empty file types.", nameof(FileTypesForVersionExpiration)); | ||
| } | ||
|
|
||
| FileTypesForVersionExpiration = FileTypesForVersionExpiration | ||
| .Distinct(StringComparer.OrdinalIgnoreCase) | ||
| .ToArray(); |
There was a problem hiding this comment.
FileTypesForVersionExpiration values are checked with IsNullOrWhiteSpace, but they are not trimmed/normalized before de-duplication and being passed to SetFileTypeVersionPolicy. Inputs like " pdf " will pass validation and be sent with leading/trailing whitespace.
Consider trimming each entry (and then re-validating for empties) before calling Distinct(...) and applying the policy.
…in SetTenant cmdlet
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
Related Issues?
Fixes #X, partially fixes #Y, mentioned in #Z, etc.
What is in this Pull Request ?
Please describe the changes in the PR.
Guidance