Skip to content
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

New cmdlet to unlock list item #4457

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}
Loading