Skip to content
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
40 changes: 31 additions & 9 deletions documentation/Restore-PnPRecycleBinItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ Restores the provided recycle bin item to its original location.
Restore-PnPRecycleBinItem -Identity <RecycleBinItemPipeBind> [-Force] [-RowLimit <Int32>]
[-Connection <PnPConnection>]
```
```powershell
Restore-PnPRecycleBinItem -IdList <string[]> [-Connection <PnPConnection>]
```

## DESCRIPTION
This cmdlet restores the specified item from the recycle bin to its original location.
This cmdlet restores the specified item or set of items from the recycle bin to its original location.

## EXAMPLES

Expand All @@ -29,14 +32,14 @@ This cmdlet restores the specified item from the recycle bin to its original loc
Restore-PnPRecycleBinItem -Identity 72e4d749-d750-4989-b727-523d6726e442
```

Restores the recycle bin item with Id 72e4d749-d750-4989-b727-523d6726e442 to its original location.
Restores the recycle bin item with Id 72e4d749-d750-4989-b727-523d6726e442 to its original location asking for confirmation to do so.

### EXAMPLE 2
```powershell
Get-PnPRecycleBinItem | ? -Property LeafName -like "*.docx" | Restore-PnPRecycleBinItem
```

Restores all the items of which the filename ends with the .docx extension from the first and second stage recycle bins to their original location.
Restores all the items of which the filename ends with the .docx extension from the first and second stage recycle bins to their original location asking for confirmation to do so.

### EXAMPLE 3
```powershell
Expand All @@ -45,6 +48,13 @@ Get-PnPRecycleBinItem -RowLimit 10000 | Restore-PnPRecycleBinItem -Force

Permanently restores up to 10,000 items in the recycle bin without asking for confirmation.

### EXAMPLE 4
```powershell
Restore-PnPRecycleBinItem -IdList @("31897b05-fd3b-4c49-9898-2e7f10e59cac","b16f0733-9b07-4ef3-a4b6-896edca4babd", "367ef9d2-6080-45ea-9a03-e8c9029f59dd")
```

Restores the recycle bin items with Id 31897b05-fd3b-4c49-9898-2e7f10e59cac, b16f0733-9b07-4ef3-a4b6-896edca4babd, 367ef9d2-6080-45ea-9a03-e8c9029f59dd to their original location.

## PARAMETERS

### -Connection
Expand All @@ -66,7 +76,7 @@ If provided, no confirmation will be asked to restore the recycle bin item.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Parameter Sets: (Restore Single Item By Id)

Required: False
Position: Named
Expand All @@ -80,7 +90,7 @@ Id of the recycle bin item or the recycle bin item object itself to restore.

```yaml
Type: RecycleBinItemPipeBind
Parameter Sets: (All)
Parameter Sets: (Restore Single Item By Id)

Required: False
Position: Named
Expand All @@ -90,20 +100,32 @@ Accept wildcard characters: False
```

### -RowLimit
Limits restoration to specified number of items.
Limits restoration to a specified number of items.

```yaml
Type: Int32
Parameter Sets: (All)
Parameter Sets: (Restore Single Item By Id)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -IdList
Array of recycle bin item GUIDs

## RELATED LINKS
```yaml
Type: String[]
Parameter Sets: (Restore Multiple Items By Id)

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
2 changes: 1 addition & 1 deletion src/Commands/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"profiles": {
"profiles": {
"PnP.PowerShell-Module": {
"commandName": "Executable",
"executablePath": "pwsh",
Expand Down
88 changes: 26 additions & 62 deletions src/Commands/RecycleBin/RestoreRecycleBinItem.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,39 @@
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System.Management.Automation;
using Resources = PnP.PowerShell.Commands.Properties.Resources;

namespace PnP.PowerShell.Commands.RecycleBin
namespace PnP.PowerShell.Commands.RecycleBin;
[Cmdlet(VerbsData.Restore, "PnPRecycleBinItem")]
[OutputType(typeof(void))]
public class RestoreRecycleBinItem : PnPSharePointCmdlethttps://github.com/pnp/powershell/pull/5199/conflict?name=src%252FCommands%252FUtilities%252FRecycleBinUtility.cs&ancestor_oid=464e3967380956cbb32b389afb9657ae6b9b2916&base_oid=09a7f7d9d33cfaea67f77b29022ef9e3f2a2f341&head_oid=8b1b9c9d30f37b07ac1d51cfd1739d24181fb366

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

Type or namespace definition, or end-of-file expected

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

} expected

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

{ expected

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

Type or namespace definition, or end-of-file expected

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

} expected

Check failure on line 8 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

{ expected
{
[Cmdlet(VerbsData.Restore, "PnPRecycleBinItem")]
[OutputType(typeof(void))]
public class RestoreRecycleBinItem : PnPSharePointCmdlet
{
[Parameter(Mandatory = false, ValueFromPipeline = true)]
public RecycleBinItemPipeBind Identity;
private const string ParameterSetName_RESTORE_MULTIPLE_ITEMS_BY_ID = "Restore Multiple Items By Id";
private const string ParameterSetName_RESTORE_SINGLE_ITEM_BY_ID = "Restore Single Items By Id";

[Parameter(Mandatory = false, ParameterSetName = ParameterSetName_RESTORE_SINGLE_ITEM_BY_ID, Position = 0, ValueFromPipeline = true)]
public RecycleBinItemPipeBind Identity;

[Parameter(Mandatory = false)]
public SwitchParameter Force;
[Parameter(Mandatory = false, ParameterSetName = ParameterSetName_RESTORE_SINGLE_ITEM_BY_ID)]
public SwitchParameter Force;

[Parameter(Mandatory = false)]
public int RowLimit;
[Parameter(Mandatory = false, ParameterSetName = ParameterSetName_RESTORE_SINGLE_ITEM_BY_ID)]
public int RowLimit;

protected override void ExecuteCmdlet()
[Parameter(Mandatory = true, ParameterSetName = ParameterSetName_RESTORE_MULTIPLE_ITEMS_BY_ID)]
public string[] IdList;

protected override void ExecuteCmdlet()
{
switch (ParameterSetName)
{
if (ParameterSpecified(nameof(Identity)))
{
// if Identity has item, use it
if (Identity.Item != null)
{
if (Force || ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, Identity.Item.LeafName), Resources.Confirm))
{
Identity.Item.Restore();
ClientContext.ExecuteQueryRetry();
}
}
else
{
var recycleBinItem = Identity.GetRecycleBinItem(Connection.PnPContext);
case ParameterSetName_RESTORE_SINGLE_ITEM_BY_ID:
RecycleBinUtility.RestoreRecycleBinItemSingle(ClientContext, this);
break;

if (recycleBinItem == null)
{
throw new PSArgumentException("Recycle bin item not found with the ID specified", nameof(Identity));
}
case ParameterSetName_RESTORE_MULTIPLE_ITEMS_BY_ID:
RecycleBinUtility.RestoreRecycleBinItemInBulk(HttpClient, ClientContext, IdList, this);
break;

if (Force || ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm))
{
recycleBinItem.Restore();
}
}
}
else
{
if (ParameterSpecified(nameof(RowLimit)))
{
if (Force || ShouldContinue(string.Format(Resources.Restore0RecycleBinItems, RowLimit), Resources.Confirm))
{
var recycleBinItemCollection = RecycleBinUtility.GetRecycleBinItemCollection(ClientContext, RowLimit, RecycleBinItemState.None);
for (var i = 0; i < recycleBinItemCollection.Count; i++)
{
var recycleBinItems = recycleBinItemCollection[i];
recycleBinItems.RestoreAll();
ClientContext.ExecuteQueryRetry();
}
}
}
else
{
if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm))
{
Connection.PnPContext.Site.RecycleBin.RestoreAll();
}
}
}
}
}
}

Check failure on line 39 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

Type or namespace definition, or end-of-file expected

Check failure on line 39 in src/Commands/RecycleBin/RestoreRecycleBinItem.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

Type or namespace definition, or end-of-file expected
Loading
Loading