Skip to content

Conversation

namwar
Copy link

@namwar namwar commented Jan 26, 2025

Type

  • Bug Fix
  • [X ] New Feature
  • Sample

What is in this Pull Request ?

Extended the functionality of Restore-PnPRecycleBinItem cmdlet by adding another parameter set. The new parameter set allows the user to provide a string array of Recycle Bin item IDs. It will enable users to deal with scenarios where many (but not all) items need to be restored.
The caller can provide a list of IDs of items to bulk restore them. Bulk restore in this case will use REST API to restore items efficiently, in bulk. It also uses a fallback logic to deal with batch errors and automatically switches to individual restore, if needed.

…ing another parameterset for providing an array of Ids of items to restore in bulk. This will allow the users to deal with the scenarios where a lot (but not all) of files need to be restored. Caller can provide a list of Ids of items to bulk restore them. Bulk restore in this case will use REST API to restore items quickly. It also uses a fall back logic to deal with batch errors and automatically switches to individual restore, if needed.
@namwar namwar changed the title Extended Restore-PnPRecycleBinItem functionality to restore selected set of items in bulk efficiently Extended Restore-PnPRecycleBinItem functionality to efficiently restore selected set of items in bulk Jan 26, 2025
@KoenZomers
Copy link
Collaborator

Thanks @namwar for your efforts! Looks cool! Left two comments for you. Would appreciate it if you could have a look at those.

…k to log reasons for failure to restore an item, in case of an error.
@namwar
Copy link
Author

namwar commented Jan 30, 2025

Please have a look at my comments on your feedback. I have clarified your concern. I think you can merge my code.

@KoenZomers
Copy link
Collaborator

Looks good @namwar, thanks!

@KoenZomers
Copy link
Collaborator

KoenZomers commented Jan 30, 2025

Still missing your change in the documentation by the way. Can you update Get-PnPRecycleBinItem.md to reflect this new option?

@KoenZomers
Copy link
Collaborator

You also don't seem to have checked the option to allow us to update your PR branch so I can add the changelog entry to it. Can you enable that please?

@namwar
Copy link
Author

namwar commented Jan 30, 2025

Thanks for your reply. I have checked and it is already checked for "Allow edits by maintainers". Am I missing something? Please guide me

image

@namwar
Copy link
Author

namwar commented Jan 30, 2025

I will update the Get-PnPRecycleBinItem.md quickly

Added information about the new parameter set.  Added example and parameter information.
@namwar
Copy link
Author

namwar commented Jan 30, 2025

I have updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look.

@namwar
Copy link
Author

namwar commented Feb 2, 2025

I had updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look, when you can.

@KoenZomers KoenZomers self-assigned this Oct 3, 2025
@KoenZomers KoenZomers requested a review from Copilot October 17, 2025 10:34
Copy link
Contributor

@Copilot 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

Adds bulk restore capability to Restore-PnPRecycleBinItem so multiple specified recycle bin item IDs can be efficiently restored in one operation with REST and fallback to individual restores on failure.

  • Introduces new parameter set with IdList (string[]) for bulk restore.
  • Implements REST-based batch restore plus fallback logic for per-item restore.
  • Updates documentation with new syntax, examples, and parameter details.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

File Description
src/Commands/Utilities/RecycleBinUtility.cs Adds bulk restore helper method using REST API with fallback to individual item restoration.
src/Commands/RecycleBin/RestoreRecycleBinItem.cs Adds new parameter set and logic branching for single vs multiple ID restoration.
documentation/Restore-PnPRecycleBinItem.md Updates usage, examples, and parameter documentation to reflect new IdList parameter set.

Comment on lines +122 to +123
string requestBody = $"{{'ids':['{idsString}']}}";
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json");
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The JSON payload is constructed with single quotes, producing invalid JSON (e.g. {'ids':['id1','id2']}) while the REST call declares application/json. Use double quotes and proper serialization to avoid malformed JSON and escaping issues: var requestBody = JsonConvert.SerializeObject(new { ids = idsList });. Apply the same fix to the fallback block later.

Copilot uses AI. Check for mistakes.

Comment on lines +138 to +139
string requestBody = $"{{'ids':['{id}']}}";
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json");
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Same malformed JSON construction as in the batch request; single quotes produce invalid JSON and unescaped values may break the request if the GUID contains unexpected characters. Replace with JsonConvert.SerializeObject(new { ids = new[]{ id } }) for correctness and safety.

Copilot uses AI. Check for mistakes.

{
string requestBody = $"{{'ids':['{idsString}']}}";
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json");
restoreRecycleBinItem.WriteVerbose("Whole batch restored successfuly.");
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'successfuly' to 'successfully'.

Copilot uses AI. Check for mistakes.

{
string requestBody = $"{{'ids':['{id}']}}";
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json");
restoreRecycleBinItem.WriteVerbose($"Item - {id} restored successfuly.");
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'successfuly' to 'successfully'.

Copilot uses AI. Check for mistakes.

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.

3 participants