diff --git a/documentation/Unlock-PnPListItemRecord.md b/documentation/Unlock-PnPListItemRecord.md new file mode 100644 index 000000000..0819476b9 --- /dev/null +++ b/documentation/Unlock-PnPListItemRecord.md @@ -0,0 +1,85 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Unlock-PnPListItemRecord.html +external help file: PnP.PowerShell.dll-Help.xml +title: Unlock-PnPListItemRecord +--- + +# Unlock-PnPListItemRecord + +## SYNOPSIS +Unlocks the list item record + + +## SYNTAX + +```powershell +Unlock-PnPListItemRecord [-List] -Identity + [-Connection ] +``` + +## DESCRIPTION + +Unlocks the list item record + +## EXAMPLES + +### EXAMPLE 1 +```powershell +Unlock-PnPListItemRecord -List "Documents" -Identity 4 +``` + +Unlocks the document in the documents library with id 4. + +## PARAMETERS + +### -Connection +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + +```yaml +Type: PnPConnection +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity +The ID of the listitem, or actual ListItem object to be unlocked + +```yaml +Type: ListItemPipeBind +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -List +The ID, Title or Url of the list. + +```yaml +Type: ListPipeBind +Parameter Sets: (All) + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) + + diff --git a/src/Commands/Lists/UnlockListItemRecord.cs b/src/Commands/Lists/UnlockListItemRecord.cs new file mode 100644 index 000000000..f1c21872a --- /dev/null +++ b/src/Commands/Lists/UnlockListItemRecord.cs @@ -0,0 +1,47 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using PnP.PowerShell.Commands.Base.PipeBinds; +using System; +using PnP.PowerShell.Commands.Utilities.REST; + +namespace PnP.PowerShell.Commands.Lists +{ + [Cmdlet(VerbsCommon.Unlock, "PnPListItemRecord")] + public class PnPListItemRecord : PnPWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)] + public ListPipeBind List; + + [Parameter(Mandatory = true, ValueFromPipeline = true)] + public ListItemPipeBind Identity; + + protected override void ExecuteCmdlet() + { + var list = List.GetList(CurrentWeb); + if (list == null) + throw new PSArgumentException($"No list found with id, title or url '{List}'", "List"); + + var item = Identity.GetListItem(list); + + WriteVerbose($"Unlock the record {Identity.Id} from list {List}"); + + ClientContext.Load(ClientContext.Site, s => s.Url); + ClientContext.ExecuteQueryRetry(); + + var payload = new + { + listUrl = list.RootFolder.ServerRelativeUrl, + itemId = Identity.Id + }; + + try + { + RestHelper.Post(Connection.HttpClient, $"{ClientContext.Site.Url}/_api/SP.CompliancePolicy.SPPolicyStoreProxy.UnlockRecordItem()", AccessToken, payload); + } + catch (Exception ex) + { + throw new Exception($"Failed to Unlock the record {Identity.Id} from list {List} with exception: {ex.Message}", ex); + } + } + } +} \ No newline at end of file