Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [3.23.2007.0] (not yet released)

### Added
- Added a `-RowLimit` parameter to `Clear-PnPRecycleBinItem` and `Restore-PnPRecycleBinItem` so that it can be used on recycle bins which hold more than 5000 items [PR #2760](https://github.com/pnp/PnP-PowerShell/pull/2760)
- Added connection option to `Connect-PnPOnline` taking `-Scopes` and `-Credentials` to allow setting up a delegated permission token for use with Microsoft Graph and the Office 365 Management API. See [this wiki page](https://github.com/pnp/PnP-PowerShell/wiki/Connect-options#connect-using-scopes-and-credentials) for more details. [PR #2746](https://github.com/pnp/PnP-PowerShell/pull/2746)
- Added Add-PnPTeamsChannel, Get-PnPTeamsApp, Get-PnPTeamsChannel, Get-PnPTeamsTab, Get-PnPTeamsTeam, Remove-PnPTeamsChannel, Remove-PnPTeamsTab, Remove-PnPTeamsTeam cmdlets

Expand All @@ -19,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Erwin van Hunen [erwinvanhunen]
- Gautam Sheth [gautamdsheth]
- Koen Zomers [koenzomers]
- Ellie Hussey [Professr]
- Todd Klindt [ToddKlindt]

## [3.22.2006.2]
Expand Down
69 changes: 52 additions & 17 deletions Commands/RecycleBin/ClearRecycleBinItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

namespace SharePointPnP.PowerShell.Commands.RecycleBin
{
[Cmdlet(VerbsCommon.Clear, "PnPRecycleBinItem", DefaultParameterSetName = "All")]
[Cmdlet(VerbsCommon.Clear, "PnPRecycleBinItem", DefaultParameterSetName = PARAMETERSET_ALL)]
[CmdletHelp("Permanently deletes all or a specific recycle bin item",
SupportedPlatform = CmdletSupportedPlatform.All,
Category = CmdletHelpCategory.RecycleBin)]
[CmdletExample(
Code = @"PS:> Get-PnPRecycleBinItem | ? FileLeafName -like ""*.docx"" | Clear-PnpRecycleBinItem",
Expand All @@ -21,52 +22,85 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin
Code = @"PS:> Clear-PnpRecycleBinItem -Identity $item -Force",
Remarks = "Permanently deletes the recycle bin item stored under variable $item from the recycle bin without asking for confirmation from the end user first",
SortOrder = 3)]
#if !SP2013
[CmdletExample(
Code = @"PS:> Clear-PnPRecycleBinItem -All -RowLimit 10000",
Remarks = "Permanently deletes up to 10,000 items in the recycle bin",
SortOrder = 4)]
#endif

public class ClearRecycleBinItem : PnPSharePointCmdlet
{
[Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item itself to permanently delete", ValueFromPipeline = true, ParameterSetName = "Identity")]
const string PARAMETERSET_ALL = "All";
const string PARAMETERSET_IDENTITY = "Identity";

[Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item itself to permanently delete", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_IDENTITY)]
public RecycleBinItemPipeBind Identity;

[Parameter(Mandatory = false, ParameterSetName = "All", HelpMessage = "Clears all items")]
[Parameter(Mandatory = false, ParameterSetName = PARAMETERSET_ALL, HelpMessage = "Clears all items")]
public SwitchParameter All;

#if !ONPREMISES
[Parameter(Mandatory = false, HelpMessage = "If provided, only all the items in the second stage recycle bin will be cleared", ParameterSetName = "All")]
[Parameter(Mandatory = false, HelpMessage = "If provided, only all the items in the second stage recycle bin will be cleared", ParameterSetName = PARAMETERSET_ALL)]
public SwitchParameter SecondStageOnly = false;
#endif
[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to permanently delete the recycle bin item")]
[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_IDENTITY)]
[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_ALL)]
public SwitchParameter Force;

#if !SP2013
[Parameter(Mandatory = false, HelpMessage = "Limits deletion to specified number of items", ParameterSetName = PARAMETERSET_ALL)]
public int RowLimit;
#endif

protected override void ExecuteCmdlet()
{
switch (ParameterSetName)
{
case "Identity":
case PARAMETERSET_IDENTITY:
var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site);

if (Force ||
ShouldContinue(string.Format(Resources.ClearRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm))
if (Force || ShouldContinue(string.Format(Resources.ClearRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm))
{
recycleBinItem.DeleteObject();
ClientContext.ExecuteQueryRetry();
}
break;
case "All":
#if !ONPREMISES
if (SecondStageOnly)
case PARAMETERSET_ALL:
#if !SP2013
if (ParameterSpecified(nameof(RowLimit)))
{
if (Force || ShouldContinue(Resources.ClearSecondStageRecycleBin, Resources.Confirm))
{
ClientContext.Site.RecycleBin.DeleteAllSecondStageItems();
if (Force || ShouldContinue(SecondStageOnly ? Resources.ClearSecondStageRecycleBin : Resources.ClearBothRecycleBins, Resources.Confirm))
{
RecycleBinItemState recycleBinStage = SecondStageOnly ? RecycleBinItemState.SecondStageRecycleBin : RecycleBinItemState.None;

RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage);
ClientContext.Load(items);
ClientContext.ExecuteQueryRetry();

items.DeleteAll();
ClientContext.ExecuteQueryRetry();
}
}
else
#endif
{
if (Force || ShouldContinue(Resources.ClearBothRecycleBins, Resources.Confirm))
#if !ONPREMISES
if (SecondStageOnly)
{
ClientContext.Site.RecycleBin.DeleteAll();
ClientContext.ExecuteQueryRetry();
if (Force || ShouldContinue(Resources.ClearSecondStageRecycleBin, Resources.Confirm))
{
ClientContext.Site.RecycleBin.DeleteAllSecondStageItems();
ClientContext.ExecuteQueryRetry();
}
}
else
{
if (Force || ShouldContinue(Resources.ClearBothRecycleBins, Resources.Confirm))
{
ClientContext.Site.RecycleBin.DeleteAll();
ClientContext.ExecuteQueryRetry();
}
}
}
break;
Expand All @@ -76,6 +110,7 @@ protected override void ExecuteCmdlet()
ClientContext.Site.RecycleBin.DeleteAll();
ClientContext.ExecuteQueryRetry();
}
}
break;
#endif
}
Expand Down
19 changes: 4 additions & 15 deletions Commands/RecycleBin/GetRecycleBinItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin
Category = CmdletHelpCategory.RecycleBin,
OutputType = typeof(RecycleBinItem),
SupportedPlatform = CmdletSupportedPlatform.All,
OutputTypeLink = "https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee541897(v=office.15)")]
OutputTypeLink = "https://docs.microsoft.com/previous-versions/office/sharepoint-server/ee541897(v=office.15)")]
[CmdletExample(
Code = @"PS:> Get-PnPRecycleBinItem",
Remarks = "Returns all items in both the first and the second stage recycle bins in the current site collection",
Expand Down Expand Up @@ -57,7 +57,7 @@ public class GetRecycleBinItems : PnPRetrievalsCmdlet<RecycleBinItem>
[Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_FIRSTSTAGE)]
[Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_SECONDSTAGE)]
[Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_ALL)]
public int RowLimit = -1;
public int RowLimit;
#endif
protected override void ExecuteCmdlet()
{
Expand All @@ -73,7 +73,7 @@ protected override void ExecuteCmdlet()
else
{
#if !SP2013
if (HasRowLimit())
if (ParameterSpecified(nameof(RowLimit)))
{
RecycleBinItemState recycleBinStage;
switch (ParameterSetName)
Expand All @@ -89,14 +89,12 @@ protected override void ExecuteCmdlet()
break;
}

RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate,
recycleBinStage);
RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage);
ClientContext.Load(items);
ClientContext.ExecuteQueryRetry();

List<RecycleBinItem> recycleBinItemList = items.ToList();
WriteObject(recycleBinItemList, true);

}
else
{
Expand All @@ -107,7 +105,6 @@ protected override void ExecuteCmdlet()

switch (ParameterSetName)
{

case ParameterSet_FIRSTSTAGE:
WriteObject(
recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.FirstStageRecycleBin), true);
Expand All @@ -121,7 +118,6 @@ protected override void ExecuteCmdlet()
WriteObject(recycleBinItemList, true);
break;
}

}
#else
ClientContext.Site.Context.Load(ClientContext.Site.RecycleBin, r => r.IncludeWithDefaultProperties(RetrievalExpressions));
Expand All @@ -148,12 +144,5 @@ protected override void ExecuteCmdlet()
#endif
}
}

#if !SP2013
private bool HasRowLimit()
{
return RowLimit > 0;
}
#endif
}
}
80 changes: 57 additions & 23 deletions Commands/RecycleBin/RestoreRecycleBinItem.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Management.Automation;
using System;
using System.Management.Automation;
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources;

namespace SharePointPnP.PowerShell.Commands.RecycleBin
{
[Cmdlet(VerbsData.Restore, "PnPRecycleBinItem")]
[Cmdlet(VerbsData.Restore, "PnPRecycleBinItem", DefaultParameterSetName = PARAMETERSET_ALL)]
[CmdletHelp("Restores the provided recycle bin item to its original location",
SupportedPlatform = CmdletSupportedPlatform.All,
Category = CmdletHelpCategory.RecycleBin)]
[CmdletExample(
Code = @"PS:> Restore-PnpRecycleBinItem -Identity 72e4d749-d750-4989-b727-523d6726e442",
Expand All @@ -17,40 +19,72 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin
Code = @"PS:> Get-PnPRecycleBinItem | ? -Property LeafName -like ""*.docx"" | Restore-PnpRecycleBinItem",
Remarks = "Restores all the items in the first and second stage recycle bins to their original location of which the filename ends with the .docx extension",
SortOrder = 2)]
#if !SP2013
[CmdletExample(
Code = @"PS:> Restore-PnPRecycleBinItem -All -RowLimit 10000",
Remarks = "Permanently restores up to 10,000 items in the recycle bin",
SortOrder = 4)]
#endif

public class RestoreRecycleBinItem : PnPSharePointCmdlet
{
[Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item object itself to restore", ValueFromPipeline = true, ParameterSetName = "Identity")]
const string PARAMETERSET_ALL = "All";
const string PARAMETERSET_IDENTITY = "Identity";

[Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item object itself to restore", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_IDENTITY)]
public RecycleBinItemPipeBind Identity;

[Parameter(Mandatory = true, HelpMessage = "If provided all items will be stored ", ValueFromPipeline = true, ParameterSetName = "All")]
[Parameter(Mandatory = false, HelpMessage = "If provided all items will be stored ", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_ALL)]
[Obsolete("No need to add the -All parameter anymore")]
public SwitchParameter All;

[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item")]
[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_IDENTITY)]
[Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_ALL)]
public SwitchParameter Force;

#if !SP2013
[Parameter(Mandatory = false, HelpMessage = "Limits restoration to specified number of items", ParameterSetName = PARAMETERSET_ALL)]
public int RowLimit;
#endif

protected override void ExecuteCmdlet()
{
if (ParameterSetName == "Identity")
{
var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site);

if (Force ||
ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName),
Resources.Confirm))
{
recycleBinItem.Restore();
ClientContext.ExecuteQueryRetry();
}
}
else
switch (ParameterSetName)
{
if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm))
{
ClientContext.Site.RecycleBin.RestoreAll();
ClientContext.ExecuteQueryRetry();
}
case PARAMETERSET_IDENTITY:
var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site);

if (Force || ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm))
{
recycleBinItem.Restore();
ClientContext.ExecuteQueryRetry();
}
break;

case PARAMETERSET_ALL:
#if !SP2013
if (ParameterSpecified(nameof(RowLimit)))
{
if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm))
{
RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, RecycleBinItemState.None);
ClientContext.Load(items);
ClientContext.ExecuteQueryRetry();

items.RestoreAll();
ClientContext.ExecuteQueryRetry();
}
}
else
#endif
{
if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm))
{
ClientContext.Site.RecycleBin.RestoreAll();
ClientContext.ExecuteQueryRetry();
}
}
break;
}
}
}
Expand Down