Skip to content

Add FileTypesForVersionExpiration parameter to Set-PnPTenant cmdlet#5278

Merged
gautamdsheth merged 2 commits intodevfrom
fix/fileversion-feat
Apr 2, 2026
Merged

Add FileTypesForVersionExpiration parameter to Set-PnPTenant cmdlet#5278
gautamdsheth merged 2 commits intodevfrom
fix/fileversion-feat

Conversation

@gautamdsheth
Copy link
Copy Markdown
Collaborator

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

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

  • You can delete this section when you are submitting the pull request.*
  • Please update this PR information accordingly. We use this as part of our release notes in monthly communications.
  • Please target your PR to Dev branch. If you do not target the Dev branch we will not accept this PR.

Copilot AI review requested due to automatic review settings April 2, 2026 18:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for specifying file-type-specific version expiration overrides when running Set-PnPTenant.

Changes:

  • Added a new -FileTypesForVersionExpiration parameter to the Set-PnPTenant cmdlet implementation.
  • Added cmdlet logic to validate the parameter and invoke Tenant.SetFileTypeVersionPolicy(...).
  • Updated Set-PnPTenant documentation 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.

Comment on lines +1892 to +1895
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));
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +1880 to +1898
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;
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
Comment on lines +1883 to +1890
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();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@gautamdsheth gautamdsheth merged commit 67c8419 into dev Apr 2, 2026
4 checks passed
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