From dbe08da826df00ad0b7adda13bd96cf97f1ef19a Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Tue, 7 Jan 2025 20:35:45 +0100 Subject: [PATCH] Fix exceptions in Restore-PnPRecycleBinItem --- src/Commands/Base/PipeBinds/RecycleBinItemPipeBind.cs | 7 +++++++ src/Commands/RecycleBin/RestoreRecycleBinItem.cs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/Commands/Base/PipeBinds/RecycleBinItemPipeBind.cs b/src/Commands/Base/PipeBinds/RecycleBinItemPipeBind.cs index cc3ca1673..011d21f33 100644 --- a/src/Commands/Base/PipeBinds/RecycleBinItemPipeBind.cs +++ b/src/Commands/Base/PipeBinds/RecycleBinItemPipeBind.cs @@ -21,6 +21,7 @@ public RecycleBinItemPipeBind() public RecycleBinItemPipeBind(RecycleBinItem item) { _item = item; + _id = item?.Id; } public RecycleBinItemPipeBind(RecycleResult result) @@ -31,6 +32,12 @@ public RecycleBinItemPipeBind(RecycleResult result) public RecycleBinItemPipeBind(IRecycleBinItem result) { _recycleBinItem = result; + _id = result?.Id; + } + + public RecycleBinItemPipeBind(Guid guid) + { + _id = guid; } public RecycleBinItemPipeBind(string id) diff --git a/src/Commands/RecycleBin/RestoreRecycleBinItem.cs b/src/Commands/RecycleBin/RestoreRecycleBinItem.cs index 18ec0ce80..228ae4cab 100644 --- a/src/Commands/RecycleBin/RestoreRecycleBinItem.cs +++ b/src/Commands/RecycleBin/RestoreRecycleBinItem.cs @@ -25,6 +25,11 @@ protected override void ExecuteCmdlet() { var recycleBinItem = Identity.GetRecycleBinItem(Connection.PnPContext); + if (recycleBinItem == null) + { + throw new PSArgumentException("Recycle bin item not found with the ID specified", nameof(Identity)); + } + if (Force || ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm)) { recycleBinItem.Restore();