Skip to content
Merged
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
110 changes: 110 additions & 0 deletions documentation/Remove-PnPFileSharingLink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPFileSharingLink.html
external help file: PnP.PowerShell.dll-Help.xml
title: Remove-PnPFileSharingLink
---

# Remove-PnPFileSharingLink

## SYNOPSIS
Removes sharing links associated with a file.

## SYNTAX

```powershell
Remove-PnPFileSharingLink -FileUrl <String> -Identity <String> -Force <SwitchParamter> [-Connection <PnPConnection>]
```

## DESCRIPTION

Removes sharing links associated with a file.

## EXAMPLES

### EXAMPLE 1
```powershell
Remove-PnPFileSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx"
```

This will delete all the sharing links associated with the `Test.docx` file in the `Shared Documents` document library.

### EXAMPLE 2
```powershell
Remove-PnPFileSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Force
```

This will delete all the sharing links associated with the `Test.docx` file in the `Shared Documents` document library. User will not be prompted for confirmation.

### EXAMPLE 3
```powershell
$sharingLinks = Get-PnPFileSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx"
Remove-PnPFileSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Identity $sharingLinks[0].Id -Force
```

This will delete the first sharing link associated with the `Test.docx` file in the `Shared Documents` document library. User will not be prompted for confirmation.

## 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
```

### -FileUrl
The file in the site

```yaml
Type: String
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Identity
The Id of the sharing link associated with the file.
You can retrieve the identity using `Get-PnPFileSharingLink` cmdlet.

```yaml
Type: Identity
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
If provided, no confirmation will be requested and the action will be performed

```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
110 changes: 110 additions & 0 deletions documentation/Remove-PnPFolderSharingLink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPFolderSharingLink.html
external help file: PnP.PowerShell.dll-Help.xml
title: Remove-PnPFolderSharingLink
---

# Remove-PnPFolderSharingLink

## SYNOPSIS
Removes sharing links associated with a folder.

## SYNTAX

```powershell
Remove-PnPFolderSharingLink -Folder <FolderPipeBind> -Identity <String> -Force <SwitchParamter> [-Connection <PnPConnection>]
```

## DESCRIPTION

Removes sharing links associated with a folder.

## EXAMPLES

### EXAMPLE 1
```powershell
Remove-PnPFolderSharingLink -Folder "/sites/demo/Shared Documents/Test"
```

This will delete all the sharing links associated with the `Test` folder in the `Shared Documents` document library.

### EXAMPLE 2
```powershell
Remove-PnPFolderSharingLink -Folder "/sites/demo/Shared Documents/Test" -Force
```

This will delete all the sharing links associated with the `Test` folder in the `Shared Documents` document library. User will not be prompted for confirmation.

### EXAMPLE 3
```powershell
$sharingLinks = Get-PnPFolderSharingLink -Folder "/sites/demo/Shared Documents/Test"
Remove-PnPFolderSharingLink -Folder "/sites/demo/Shared Documents/Test" -Identity $sharingLinks[0].Id -Force
```

This will delete the first sharing link associated with the `Test` folder in the `Shared Documents` document library. User will not be prompted for confirmation.

## 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
```

### -Folder
The folder in the site

```yaml
Type: FolderPipeBind
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Identity
The Id of the sharing link associated with the folder.
You can retrieve the identity using `Get-PnPFolderSharingLink` cmdlet.

```yaml
Type: Identity
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
If provided, no confirmation will be requested and the action will be performed

```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
2 changes: 1 addition & 1 deletion src/Commands/Apps/RemoveApplicationCustomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void ExecuteCmdlet()

if (!actions.Any())
{
WriteVerbose($"No application customimzers representing the client side extension registration found within the scope '{Scope}'");
WriteVerbose($"No application customizers representing the client side extension registration found within the scope '{Scope}'");
return;
}

Expand Down
75 changes: 75 additions & 0 deletions src/Commands/Security/RemoveFileSharingLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.Office.SharePoint.Tools;
using PnP.Framework.Utilities;
using PnP.PowerShell.Commands.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Security
{
[Cmdlet(VerbsCommon.Remove, "PnPFileSharingLink")]
[OutputType(typeof(void))]
public class RemoveFileSharingLink : PnPWebCmdlet
{
[Parameter(Mandatory = true)]
public string FileUrl;

[Parameter(Mandatory = false)]
public string Identity;

[Parameter(Mandatory = false)]
public SwitchParameter Force;

protected override void ExecuteCmdlet()
{
var serverRelativeUrl = string.Empty;
var ctx = Connection.PnPContext;

ctx.Web.EnsureProperties(w => w.ServerRelativeUrl);

if (!FileUrl.ToLower().StartsWith(ctx.Web.ServerRelativeUrl.ToLower()))
{
serverRelativeUrl = UrlUtility.Combine(ctx.Web.ServerRelativeUrl, FileUrl);
}
else
{
serverRelativeUrl = FileUrl;
}

var file = ctx.Web.GetFileByServerRelativeUrl(serverRelativeUrl);

var sharingLinks = file.GetShareLinks();

if (sharingLinks?.RequestedItems != null && sharingLinks.Length > 0)
{
if (ParameterSpecified(nameof(Identity)) && !string.IsNullOrEmpty(Identity))
{
var link = sharingLinks.Where(s => s.Id == Identity).FirstOrDefault();
if (link != null)
{
if (Force || ShouldContinue($"Remove Sharing Link with ID {Identity} ?", Resources.Confirm))
{
link.DeletePermission();
}
}
else
{
throw new PSArgumentException($"Sharing link with ID {Identity} not found");
}
}
else
{
if (Force || ShouldContinue($"Remove all sharing links associated with the file ?", Resources.Confirm))
{
file.DeleteShareLinks();
}
}
}
else
{
throw new PSArgumentException("No sharing links were found for the specified file");
}
}
}
}
64 changes: 64 additions & 0 deletions src/Commands/Security/RemoveFolderSharingLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Office.SharePoint.Tools;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Properties;
using System.Linq;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Security
{
[Cmdlet(VerbsCommon.Remove, "PnPFolderSharingLink")]
[OutputType(typeof(void))]
public class RemoveFolderSharingLink : PnPWebCmdlet
{
[Parameter(Mandatory = true)]
public FolderPipeBind Folder;

[Parameter(Mandatory = false)]
public string Identity;

[Parameter(Mandatory = false)]
public SwitchParameter Force;

protected override void ExecuteCmdlet()
{
var serverRelativeUrl = string.Empty;
var ctx = Connection.PnPContext;

ctx.Web.EnsureProperties(w => w.ServerRelativeUrl);

var folder = Folder.GetFolder(ctx);

var sharingLinks = folder.GetShareLinks();

if (sharingLinks?.RequestedItems != null && sharingLinks.Length > 0)
{
if (ParameterSpecified(nameof(Identity)) && !string.IsNullOrEmpty(Identity))
{
var link = sharingLinks.Where(s => s.Id == Identity).FirstOrDefault();
if (link != null)
{
if (Force || ShouldContinue($"Remove Sharing Link with ID {Identity} ?", Resources.Confirm))
{
link.DeletePermission();
}
}
else
{
throw new PSArgumentException($"Sharing link with ID {Identity} not found");
}
}
else
{
if (Force || ShouldContinue($"Remove all sharing links associated with the folder ?", Resources.Confirm))
{
folder.DeleteShareLinks();
}
}
}
else
{
throw new PSArgumentException("No sharing links were found for the specified folder");
}
}
}
}