diff --git a/documentation/Remove-PnPFileSharingLink.md b/documentation/Remove-PnPFileSharingLink.md new file mode 100644 index 000000000..515690278 --- /dev/null +++ b/documentation/Remove-PnPFileSharingLink.md @@ -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 -Identity -Force [-Connection ] +``` + +## 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) diff --git a/documentation/Remove-PnPFolderSharingLink.md b/documentation/Remove-PnPFolderSharingLink.md new file mode 100644 index 000000000..4b7aac750 --- /dev/null +++ b/documentation/Remove-PnPFolderSharingLink.md @@ -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 -Identity -Force [-Connection ] +``` + +## 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) diff --git a/src/Commands/Apps/RemoveApplicationCustomizer.cs b/src/Commands/Apps/RemoveApplicationCustomizer.cs index ea90b2e42..18c3cf796 100644 --- a/src/Commands/Apps/RemoveApplicationCustomizer.cs +++ b/src/Commands/Apps/RemoveApplicationCustomizer.cs @@ -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; } diff --git a/src/Commands/Security/RemoveFileSharingLink.cs b/src/Commands/Security/RemoveFileSharingLink.cs new file mode 100644 index 000000000..17317a05d --- /dev/null +++ b/src/Commands/Security/RemoveFileSharingLink.cs @@ -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"); + } + } + } +} diff --git a/src/Commands/Security/RemoveFolderSharingLink.cs b/src/Commands/Security/RemoveFolderSharingLink.cs new file mode 100644 index 000000000..a432cd4ac --- /dev/null +++ b/src/Commands/Security/RemoveFolderSharingLink.cs @@ -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"); + } + } + } +}