-
Notifications
You must be signed in to change notification settings - Fork 388
Extended Restore-PnPRecycleBinItem functionality to efficiently restore selected set of items in bulk #4705
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
base: dev
Are you sure you want to change the base?
Conversation
…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.
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.
Please have a look at my comments on your feedback. I have clarified your concern. I think you can merge my code. |
Looks good @namwar, thanks! |
Still missing your change in the documentation by the way. Can you update Get-PnPRecycleBinItem.md to reflect this new option? |
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? |
I will update the Get-PnPRecycleBinItem.md quickly |
Added information about the new parameter set. Added example and parameter information.
I have updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look. |
I had updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look, when you can. |
There was a problem hiding this 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. |
string requestBody = $"{{'ids':['{idsString}']}}"; | ||
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
string requestBody = $"{{'ids':['{id}']}}"; | ||
REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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."); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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."); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Type
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.