Skip to content

Commit

Permalink
[FileVersion] Add and update batch delete cmdlets
Browse files Browse the repository at this point in the history
  • Loading branch information
jennywu committed Mar 13, 2024
1 parent 80fea6c commit 00bb7d2
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 107 deletions.
65 changes: 65 additions & 0 deletions documentation/Get-PnPLibraryFileVersionBatchDeleteJobProgress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPLibraryFileVersionBatchDeleteJobProgress.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPLibraryFileVersionBatchDeleteJobProgress
---

# Get-PnPLibraryFileVersionBatchDeleteJobProgress

## SYNOPSIS
Get the progress of deleting existing file versions on the document library.

## SYNTAX

```powershell
Get-PnPLibraryFileVersionBatchDeleteJobProgress -Identity <ListPipeBind> [-Connection <PnPConnection>]
```

## DESCRIPTION
This cmdlet allows retrieval of the progress of deleting existing file versions on the document library.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPLibraryFileVersionBatchDeleteJobProgress -Identity "Documents"
```

Returns the progress of deleting existing file versions on the document library.

## PARAMETERS

### -Identity
The ID, name or Url (Lists/MyList) of the document library to perform the trimming on.

```yaml
Type: ListPipeBind
Parameter Sets: (All)

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.
```yaml
Type: PnPConnection
Parameter Sets: (All)

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)
51 changes: 51 additions & 0 deletions documentation/Get-PnPSiteFileVersionBatchDeleteJobProgress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPSiteFileVersionBatchDeleteJobProgress.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPSiteFileVersionBatchDeleteJobProgress
---

# Get-PnPSiteFileVersionBatchDeleteJobProgress

## SYNOPSIS
Get the progress of deleting existing file versions on the site.

## SYNTAX

```powershell
Get-PnPSiteFileVersionBatchDeleteJobProgress [-Connection <PnPConnection>]
```

## DESCRIPTION
This cmdlet allows retrieval of the progress of deleting existing file versions on the site.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPSiteFileVersionBatchDeleteJobProgress
```

Returns the progress of deleting existing file versions on the site.

## PARAMETERS

### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
Parameter Sets: (All)

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)
62 changes: 59 additions & 3 deletions documentation/New-PnPLibraryFileVersionBatchDeleteJob.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ Starts a file version batch trim job for a document library.
New-PnPLibraryFileVersionBatchDeleteJob -Identity "Documents" -DeleteBeforeDays 360
```

Starts a file version batch trim job that will delete all file verions that are over 360 days old in the document library.
Starts a file version batch trim job that will delete all file versions that are over 360 days old in the document library.

### EXAMPLE 2
```powershell
New-PnPLibraryFileVersionBatchDeleteJob -Identity "Documents" -DeleteBeforeDays 360 -Force
```

Starts a file version batch trim job that will delete all file verions that are over 360 days old in the document library, without prompting the user for confirmation.
Starts a file version batch trim job that will delete all file versions that are over 360 days old in the document library, without prompting the user for confirmation.

### EXAMPLE 3
```powershell
New-PnPLibraryFileVersionBatchDeleteJob -Automatic
```

Starts a file version batch trim job that will delete file versions that expiread and set version expiration time for the ones not expired in the document library based on the backend algorithm.

### EXAMPLE 4
```powershell
New-PnPLibraryFileVersionBatchDeleteJob -MajorVersionLimit 30 -MajorWithMinorVersionsLimit 10
```

Starts a file version batch trim job that will delete file versions in the document library based on the version count limits.

## PARAMETERS

Expand All @@ -60,7 +74,7 @@ The minimum age of file versions to trim. In other words, all file versions that
```yaml
Type: int
Parameter Sets: (All)
Parameter Sets: DeleteOlderThanDays

Required: True
Position: Named
Expand All @@ -69,6 +83,48 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Automatic
Trim file version using automatic trim.
```yaml
Type: SwitchParameter
Parameter Sets: AutomaticTrim

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -MajorVersionLimit
Trim file version using version count limits. Need to specify MajorWithMinorVersionsLimit as well.
```yaml
Type: int
Parameter Sets: CountLimits

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -MajorWithMinorVersionsLimit
Trim file version using version count limits. Need to specify MajorVersionLimit as well.
```yaml
Type: int
Parameter Sets: CountLimits

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Force
When provided, no confirmation prompts will be shown to the user.
Expand Down
62 changes: 59 additions & 3 deletions documentation/New-PnPSiteFileVersionBatchDeleteJob.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ Starts a file version batch trim job targeting all document libraries in a site
New-PnPSiteFileVersionBatchDeleteJob -DeleteBeforeDays 360
```

Starts a file version batch trim job that will delete all file verions that are over 360 days old in all document libraries in the site collection.
Starts a file version batch trim job that will delete all file versions that are over 360 days old in all document libraries in the site collection.

### EXAMPLE 2
```powershell
New-PnPSiteFileVersionBatchDeleteJob -DeleteBeforeDays 360 -Force
```

Starts a file version batch trim job that will delete all file verions that are over 360 days old in all document libraries in the site collection, without prompting the user for confirmation.
Starts a file version batch trim job that will delete all file versions that are over 360 days old in all document libraries in the site collection, without prompting the user for confirmation.

### EXAMPLE 3
```powershell
New-PnPSiteFileVersionBatchDeleteJob -Automatic
```

Starts a file version batch trim job that will delete file versions that expiread and set version expiration time for the ones not expired in the site collection based on the backend algorithm.

### EXAMPLE 4
```powershell
New-PnPSiteFileVersionBatchDeleteJob -MajorVersionLimit 30 -MajorWithMinorVersionsLimit 10
```

Starts a file version batch trim job that will delete file versions in the site collection based on the version count limits.

## PARAMETERS

Expand All @@ -46,7 +60,7 @@ The minimum age of file versions to trim. In other words, all file versions that

```yaml
Type: int
Parameter Sets: (All)
Parameter Sets: DeleteOlderThanDays

Required: True
Position: Named
Expand All @@ -55,6 +69,48 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Automatic
Trim file version using automatic trim.
```yaml
Type: SwitchParameter
Parameter Sets: AutomaticTrim

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -MajorVersionLimit
Trim file version using version count limits. Need to specify MajorWithMinorVersionsLimit as well.
```yaml
Type: int
Parameter Sets: CountLimits

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -MajorWithMinorVersionsLimit
Trim file version using version count limits. Need to specify MajorVersionLimit as well.
```yaml
Type: int
Parameter Sets: CountLimits

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Force
When provided, no confirmation prompts will be shown to the user.
Expand Down
58 changes: 58 additions & 0 deletions src/Commands/Lists/GetLibraryFileVersionBatchDeleteJobProgress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.SharePoint.Client;

using PnP.Framework.Utilities;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Model.SharePoint;
using System;
using System.Management.Automation;
using System.Text.Json;

namespace PnP.PowerShell.Commands.Lists
{
[Cmdlet(VerbsCommon.Get, "PnPLibraryFileVersionBatchDeleteJobProgress")]
[OutputType(typeof(FileVersionBatchDeleteJobProgress))]
public class GetLibraryFileVersionBatchDeleteJobProgress : PnPWebCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
[ValidateNotNull]
public ListPipeBind Identity;

protected override void ExecuteCmdlet()
{
var list = Identity.GetList(CurrentWeb);
if (list != null)
{
var ret = list.GetProgressForDeleteFileVersions();

Check failure on line 25 in src/Commands/Lists/GetLibraryFileVersionBatchDeleteJobProgress.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'List' does not contain a definition for 'GetProgressForDeleteFileVersions' and no accessible extension method 'GetProgressForDeleteFileVersions' accepting a first argument of type 'List' could be found (are you missing a using directive or an assembly reference?)
ClientContext.ExecuteQueryRetry();

var progress = JsonSerializer.Deserialize<FileVersionBatchDeleteJobProgress>(ret.Value);
var connectionUrl = new Uri(Connection.Url);
var serverUrl = string.Concat("https://", connectionUrl.Host);
progress.Url = string.Concat(serverUrl, list.RootFolder.ServerRelativeUrl);

if (!string.Equals(progress.BatchDeleteMode, FileVersionBatchDeleteMode.DeleteOlderThanDays.ToString(), StringComparison.OrdinalIgnoreCase))

Check failure on line 33 in src/Commands/Lists/GetLibraryFileVersionBatchDeleteJobProgress.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'FileVersionBatchDeleteMode' does not exist in the current context
{
progress.DeleteOlderThan = string.Empty;
}

if (!string.Equals(progress.BatchDeleteMode, FileVersionBatchDeleteMode.CountLimits.ToString(), StringComparison.OrdinalIgnoreCase))

Check failure on line 38 in src/Commands/Lists/GetLibraryFileVersionBatchDeleteJobProgress.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'FileVersionBatchDeleteMode' does not exist in the current context
{
progress.MajorVersionLimit = string.Empty;
progress.MajorWithMinorVersionsLimit = string.Empty;
}

if (string.Equals(progress.LastProcessTimeInUTC, DateTime.MinValue.ToString()))
{
progress.LastProcessTimeInUTC = string.Empty;
}

if (string.Equals(progress.CompleteTimeInUTC, DateTime.MinValue.ToString()))
{
progress.CompleteTimeInUTC = string.Empty;
}

WriteObject(progress);
}
}
}
}
Loading

0 comments on commit 00bb7d2

Please sign in to comment.