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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-SharingStatus` parameter to `Get-PnPFlow` which allows for filtering flows based on their sharing status. [#3287](https://github.com/pnp/powershell/pull/3287)
- Added `-AzureADLoginEndPoint` and `-MicrosoftGraphEndPoint` parameters to `Connect-PnPOnline` cmdlet for use in custom Azure environments. [#2925](https://github.com/pnp/powershell/pull/2925)
- Added `SiteOwnerManageLegacyServicePrincipalEnabled` parameter to `Set-PnPTenant` cmdlet. With this parameter site owners will not be able to register/update apps unless the tenant admin explicitly allows it. [#3318](https://github.com/pnp/powershell/pull/3318)

- Added `-EnableAutoExpirationVersionTrim`, `-ExpireVersionsAfterDays`, `-MajorVersions`, `-MinorVersions`, `-InheritTenantVersionPolicySettings`, `-StartApplyVersionPolicySettingToExistingDocLibs` and `-CancelApplyVersionPolicySettingToExistingDocLibs` to `Set-PnPSite` to allow for time based version expiration on the site level [#3373](https://github.com/pnp/powershell/pull/3373)

### Fixed

- Fixed `Add-PnPContentTypeToList` cmdlet to better handle piped lists. [#3244](https://github.com/pnp/powershell/pull/3244)
Expand All @@ -45,6 +46,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Contributors

- [msjennywu]
- Reshmee Auckloo [reshmee011]
- Per Østergaard [per-oestergaard]
- Nishkalank Bezawada [NishkalankBezawada]
Expand Down
166 changes: 166 additions & 0 deletions documentation/Set-PnPSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Set-PnPSite [-Identity <String>]
[-BlockDownloadPolicy <Boolean>] [-ExcludeBlockDownloadPolicySiteOwners <Boolean>]
[-ExcludedBlockDownloadGroupIds <Guid[]>]
[-ListsShowHeaderAndNavigation <Boolean>]
[-EnableAutoExpirationVersionTrim <Boolean>]
[-ExpireVersionsAfterDays <UInt32>]
[-MajorVersions <UInt32>]
[-MinorVersions <UInt32>]
[-InheritTenantVersionPolicySettings]
[-StartApplyVersionPolicySettingToExistingDocLibs]
[-CancelApplyVersionPolicySettingToExistingDocLibs]
[-Connection <PnPConnection>]
```

Expand Down Expand Up @@ -103,6 +110,62 @@ Set-PnPSite -NoScriptSite $false

Allows custom script on a specific site. See [Allow or prevent custom script](https://learn.microsoft.com/sharepoint/allow-or-prevent-custom-script) for more information.

### EXAMPLE 7
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $true
```

Set AutoExpiration file version trim mode for a site. The new document libraries will use this version setting.

### EXAMPLE 8
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -ExpireVersionsAfterDays 200
```

Set ExpireAfter file version trim mode for a site. The new document libraries will use this version setting.

### EXAMPLE 9
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 300 -ExpireVersionsAfterDays 0
```

Set NoExpiration file version trim mode for a site. The new document libraries will use this version setting.

### EXAMPLE 10
```powershell
Set-PnPSite -InheritTenantVersionPolicySettings
```

Clear the file version setting on a site. The new document libraries will use the tenant level setting.

### EXAMPLE 11
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $true -StartApplyVersionPolicySettingToExistingDocLibs
```

Create a request to set the file version trim mode as AutoExpiration for existing document libraries that enabled versioning.

### EXAMPLE 12
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -MinorVersions 5 -ExpireVersionsAfterDays 200 -StartApplyVersionPolicySettingToExistingDocLibs
```

Create a request to set the file version trim mode as ExpireAfter for existing document libraries that enabled versioning.

### EXAMPLE 13
```powershell
Set-PnPSite -EnableAutoExpirationVersionTrim $false -MajorVersions 100 -MinorVersions 5 -ExpireVersionsAfterDays 0 -StartApplyVersionPolicySettingToExistingDocLibs
```

Create a request to set the file version trim mode as NoExpiration for existing document libraries that enabled versioning.

### EXAMPLE 14
```powershell
Set-PnPSite -CancelApplyVersionPolicySettingToExistingDocLibs
```

Cancel the existing request which sets the file version trim mode for existing document libraries on a site.

## PARAMETERS

### -AllowSelfServiceUpgrade
Expand Down Expand Up @@ -613,6 +676,109 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableAutoExpirationVersionTrim
Enable or disable AutoExpiration version trim for the document libraries on the site. Set to $true to enable, $false to disable.

Parameter ExpireVersionsAfterDays is required when EnableAutoExpirationVersionTrim is false. Set it to 0 for NoExpiration, set it to greater or equal to 30 for ExpireAfter.

Parameter MajorVersions is required when EnableAutoExpirationVersionTrim is false.
Parameter MinorVersions is required when EnableAutoExpirationVersionTrim is false and StartApplyVersionPolicySettingToExistingDocLibs is specified. It is used when minor version is enabled on the document libraries.

```yaml
Type: Boolean
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ExpireVersionsAfterDays
Work with parameter EnableAutoExpirationVersionTrim. Please see description in EnableAutoExpirationVersionTrim.

```yaml
Type: UInt32
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -MajorVersions
Work with parameter EnableAutoExpirationVersionTrim. Please see description in EnableAutoExpirationVersionTrim.

```yaml
Type: UInt32
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -MinorVersions
Work with parameter EnableAutoExpirationVersionTrim and StartApplyVersionPolicySettingToExistingDocLibs. Please see description in EnableAutoExpirationVersionTrim.

```yaml
Type: UInt32
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -InheritTenantVersionPolicySettings
Clear the file version setting on a site. The new document libraries will use the tenant level setting.

```yaml
Type: SwitchParameter
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -StartApplyVersionPolicySettingToExistingDocLibs
Create a request to set the file version trim mode for existing document libraries that enabled versioning. Work with parameters EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersions and MinorVersions.

```yaml
Type: SwitchParameter
Parameter Sets: Set Properties

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -CancelApplyVersionPolicySettingToExistingDocLibs
Cancel the existing request which sets the file version trim mode for existing document libraries on a site.

```yaml
Type: SwitchParameter
Parameter Sets: Set Properties

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)
Expand Down
140 changes: 140 additions & 0 deletions src/Commands/Site/SetSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ public class SetSite : PnPSharePointCmdlet
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_LOCKSTATE)]
public SwitchParameter Wait;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public bool EnableAutoExpirationVersionTrim;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public int ExpireVersionsAfterDays;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public int MajorVersions;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public int MinorVersions;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public SwitchParameter InheritTenantVersionPolicySettings;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public SwitchParameter StartApplyVersionPolicySettingToExistingDocLibs;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_PROPERTIES)]
public SwitchParameter CancelApplyVersionPolicySettingToExistingDocLibs;

protected override void ExecuteCmdlet()
{
var context = ClientContext;
Expand Down Expand Up @@ -235,6 +256,125 @@ protected override void ExecuteCmdlet()
}
}

if (ParameterSpecified(nameof(InheritTenantVersionPolicySettings)))
{
if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)) ||
ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
ParameterSpecified(nameof(MajorVersions)) ||
ParameterSpecified(nameof(MinorVersions)) ||
ParameterSpecified(nameof(StartApplyVersionPolicySettingToExistingDocLibs)) ||
ParameterSpecified(nameof(CancelApplyVersionPolicySettingToExistingDocLibs)))
{
throw new PSArgumentException($"The VersionPolicy related parameters (EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersions, StartApplyVersionPolicySettingToExistingDocLibs, CancelApplyVersionPolicySettingToExistingDocLibs) cannot be set when InheritTenantVersionPolicySettings is specified.");
}

site.EnsureProperty(s => s.VersionPolicyForNewLibrariesTemplate);
site.VersionPolicyForNewLibrariesTemplate.InheritTenantSettings();
context.ExecuteQueryRetry();
}
else
{
if (ParameterSpecified(nameof(StartApplyVersionPolicySettingToExistingDocLibs)) &&
ParameterSpecified(nameof(CancelApplyVersionPolicySettingToExistingDocLibs)))
{
throw new PSArgumentException($"Don't specify both StartApplyVersionPolicySettingToExistingDocLibs and CancelApplyVersionPolicySettingToExistingDocLibs.");
}

if (ParameterSpecified(nameof(CancelApplyVersionPolicySettingToExistingDocLibs)))
{
if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)) ||
ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
ParameterSpecified(nameof(MajorVersions)) ||
ParameterSpecified(nameof(MinorVersions)))
{
throw new PSArgumentException($"The VersionPolicy related parameters (EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersions) cannot be set when CancelApplyVersionPolicySettingToExistingDocLibs is specified.");
}

site.CancelSetVersionPolicyForDocLibs();
context.ExecuteQueryRetry();
}
else
{
if (ParameterSpecified(nameof(StartApplyVersionPolicySettingToExistingDocLibs)))
{
if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)))
{
if (EnableAutoExpirationVersionTrim)
{
if (ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
ParameterSpecified(nameof(MajorVersions)) ||
ParameterSpecified(nameof(MinorVersions)))
{
throw new PSArgumentException($"Don't specify ExpireVersionsAfterDays, MajorVersions and MinorVersions when EnableAutoExpirationVersionTrim is true.");
}

site.StartSetVersionPolicyForDocLibs(true, -1, -1, -1);
context.ExecuteQueryRetry();
}
else
{
if (!ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
!ParameterSpecified(nameof(MajorVersions)) ||
!ParameterSpecified(nameof(MinorVersions)))
{
throw new PSArgumentException($"You must specify ExpireVersionsAfterDays, MajorVersions and MinorVersions when EnableAutoExpirationVersionTrim is false.");
}

site.StartSetVersionPolicyForDocLibs(false, MajorVersions, MinorVersions, ExpireVersionsAfterDays);
context.ExecuteQueryRetry();
}
}
else
{
throw new PSArgumentException($"You must specify EnableAutoExpirationVersionTrim when StartApplyVersionPolicySettingToExistingDocLibs is specified.");
}
}
else
{
if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)))
{
if (ParameterSpecified(nameof(MinorVersions)))
{
throw new PSArgumentException($"Don't specify MinorVersions when StartApplyVersionPolicySettingToExistingDocLibs is not specified.");
}

if (EnableAutoExpirationVersionTrim)
{
if (ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
ParameterSpecified(nameof(MajorVersions)))
{
throw new PSArgumentException($"Don't specify ExpireVersionsAfterDays and MajorVersions when EnableAutoExpirationVersionTrim is true.");
}

site.EnsureProperty(s => s.VersionPolicyForNewLibrariesTemplate);
site.VersionPolicyForNewLibrariesTemplate.SetAutoExpiration();
context.ExecuteQueryRetry();
}
else
{
if (!ParameterSpecified(nameof(ExpireVersionsAfterDays)) ||
!ParameterSpecified(nameof(MajorVersions)))
{
throw new PSArgumentException($"You must specify ExpireVersionsAfterDays and MajorVersions when EnableAutoExpirationVersionTrim is false.");
}

site.EnsureProperty(s => s.VersionPolicyForNewLibrariesTemplate);
if (ExpireVersionsAfterDays == 0)
{
site.VersionPolicyForNewLibrariesTemplate.SetNoExpiration(MajorVersions);
context.ExecuteQueryRetry();
}
else
{
site.VersionPolicyForNewLibrariesTemplate.SetExpireAfter(MajorVersions, ExpireVersionsAfterDays);
context.ExecuteQueryRetry();
}
}
}
}
}
}

if (IsTenantProperty())
{
var tenantAdminUrl = UrlUtilities.GetTenantAdministrationUrl(context.Url);
Expand Down
Loading