Skip to content

Commit

Permalink
New cmdlet to unlock list item
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmee011 authored and gautamdsheth committed Nov 23, 2024
1 parent 8698e94 commit 89edb71
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
85 changes: 85 additions & 0 deletions documentation/Unlock-PnPListItemRecord.md
Original file line number Diff line number Diff line change
@@ -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] <ListPipeBind> -Identity <ListItemPipeBind>
[-Connection <PnPConnection>]
```

## 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)
47 changes: 47 additions & 0 deletions src/Commands/Lists/UnlockListItemRecord.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}

0 comments on commit 89edb71

Please sign in to comment.