-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8698e94
commit 89edb71
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |