Skip to content

Commit 8d01984

Browse files
authored
Merge pull request #5489 from pnp/feat/1895-expiretime
Add expiration date parameter to sharing link commands
2 parents eea3e08 + e285bce commit 8d01984

5 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2828
- Added `Set-PnPContainerApplicationPermission` to set the permissions of an application on the containers of a SharePoint Embedded container type registered in the tenant, through Microsoft Graph. [#5488](https://github.com/pnp/powershell/pull/5488)
2929
- Added `New-PnPContainer` and `Enable-PnPContainer` to create and activate a SharePoint Embedded container through Microsoft Graph. [#5488](https://github.com/pnp/powershell/pull/5488)
3030
- Added `-Name`, `-Description`, `-OcrEnabled`, `-ItemVersioningEnabled` and `-ItemMajorVersionLimit` to `Set-PnPContainer`, which change those settings of a container through Microsoft Graph. [#5488](https://github.com/pnp/powershell/pull/5488)
31+
- Added `-ExpirationDateTime` to `Add-PnPFolderUserSharingLink` and `Add-PnPFileUserSharingLink`, so a sharing link for specific people stops working after the given date. [#5484](https://github.com/pnp/powershell/issues/5484)
3132
- Added `-AllowLegacyAuthProtocolsEnabledSetting`, `-AllowLegacyBrowserAuthProtocolsEnabledSetting`, `-AppAccessInformationBarriersAllowList`, `-AppOnlyBypassPeoplePickerPolicies`, `-BlockAppAccessWithAuthenticationContext`, `-BlockDownloadLinksFileType`, `-BlockUserInfoVisibility`, `-CoreAnyoneSharingLinkMaxExpirationInDays`, `-CoreAnyoneSharingLinkRecommendedExpirationInDays`, `-DefaultContentCenterSite`, `-DefaultLanguageForSiteCreation`, `-DelegateRestrictedAccessControlManagement`, `-DelegateRestrictedContentDiscoverabilityManagement`, `-DisableSharePointStoreAccess`, `-DisableSpfxTopBottomPlaceholdersInElevatedContent`, `-DisableTeamsMeetingRecordingDeletedNotification`, `-EnableAgentWorkerSharingDisclaimer`, `-FilePreviewAllowedDomainList`, `-IsFilePreviewDomainRestrictionEnabled`, `-IsSharePointAddInsBlocked`, `-LimitedAccessFileType`, `-MassDeleteNotificationDisabledForODB`, `-MassDeleteNotificationDisabledForSPO`, `-OneDriveAnyoneSharingLinkMaxExpirationInDays`, `-OneDriveAnyoneSharingLinkRecommendedExpirationInDays`, `-PermissiveBrowserFileHandlingOverride`, `-RemoveVersionExpirationFileTypeOverride`, `-RestrictedAccessControlForOneDriveErrorHelpLink`, `-ReSyncTenantPrivacyProfile`, `-SiteOwnersCanAccessMissingContent`, `-StopAlerts`, `-StopNew2010Workflows`, `-SyncPrivacyProfileProperties`, `-UnlicensedOneDriveAccountsActiveStoragePeriod`, `-WhoCanShareAnonymousAllowList`, `-WhoCanShareAuthenticatedGuestAllowList` and `-Workflows2013Enabled` to `Set-PnPTenant`, and `-DisableWorkflow2010` as an alias of `-Workflow2010Disabled`, matching `Set-SPOTenant`. `Get-PnPTenant` now returns the values of these settings, including `WhoCanShareAnonymousAllowList` and `WhoCanShareAuthenticatedGuestAllowList`, which it always returned empty before. [#5491](https://github.com/pnp/powershell/pull/5491)
3233

3334
### Changed

‎documentation/Add-PnPFileUserSharingLink.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Creates a sharing link to share a file with a list of specified users.
1515
## SYNTAX
1616

1717
```powershell
18-
Add-PnPFileUserSharingLink -FileUrl <String> -Type <PnP.Core.Model.Security.ShareType> -Users <String[]> [-Connection <PnPConnection>]
18+
Add-PnPFileUserSharingLink -FileUrl <String> -Users <String[]> [-ShareType <PnP.Core.Model.Security.ShareType>] [-ExpirationDateTime <DateTime>] [-Connection <PnPConnection>]
1919
```
2020

2121
## DESCRIPTION
@@ -33,11 +33,18 @@ This will create an user sharing link for `Test.docx` file in the `Shared Docume
3333

3434
### EXAMPLE 2
3535
```powershell
36-
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Type Edit -Users "john@contoso.onmicrosoft.com","jane@contoso.onmicrosoft.com"
36+
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -ShareType Edit -Users "john@contoso.onmicrosoft.com","jane@contoso.onmicrosoft.com"
3737
```
3838

3939
This will create an user sharing link for `Test.docx` file in the `Shared Documents` library which will be editable by specified users in the organization.
4040

41+
### EXAMPLE 3
42+
```powershell
43+
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Users "john@contoso.onmicrosoft.com" -ExpirationDateTime (Get-Date).AddDays(15)
44+
```
45+
46+
This will create an user sharing link for `Test.docx` file in the `Shared Documents` library which will be viewable by the specified user. The link will stop working after 15 days.
47+
4148
## PARAMETERS
4249

4350
### -Connection
@@ -54,6 +61,20 @@ Accept pipeline input: False
5461
Accept wildcard characters: False
5562
```
5663
64+
### -ExpirationDateTime
65+
The date and time after which the sharing link stops working. A value without a time zone, such as `(Get-Date).AddDays(15)` or `"2026-12-31 18:00"`, is treated as local time. When not specified, the link does not expire unless an expiration policy applies to the tenant or site.
66+
67+
```yaml
68+
Type: DateTime
69+
Parameter Sets: (All)
70+
71+
Required: False
72+
Position: Named
73+
Default value: None
74+
Accept pipeline input: False
75+
Accept wildcard characters: False
76+
```
77+
5778
### -FileUrl
5879
The file in the site
5980

‎documentation/Add-PnPFolderUserSharingLink.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Creates a sharing link to share a folder with a list of specified users.
1515
## SYNTAX
1616

1717
```powershell
18-
Add-PnPFolderUserSharingLink -Folder <FolderPipeBind> -ShareType <PnP.Core.Model.Security.ShareType> -Users <String[]> [-Connection <PnPConnection>]
18+
Add-PnPFolderUserSharingLink -Folder <FolderPipeBind> -Users <String[]> [-ShareType <PnP.Core.Model.Security.ShareType>] [-ExpirationDateTime <DateTime>] [-Connection <PnPConnection>]
1919
```
2020

2121
## DESCRIPTION
@@ -38,6 +38,13 @@ Add-PnPFolderUserSharingLink -Folder "/sites/demo/Shared Documents/Test" -ShareT
3838

3939
This will create an user sharing link for `Test` folder in the `Shared Documents` library which will be editable by specified users in the organization.
4040

41+
### EXAMPLE 3
42+
```powershell
43+
Add-PnPFolderUserSharingLink -Folder "/sites/demo/Shared Documents/Test" -Users "john@contoso.onmicrosoft.com" -ExpirationDateTime (Get-Date).AddDays(15)
44+
```
45+
46+
This will create an user sharing link for `Test` folder in the `Shared Documents` library which will be viewable by the specified user. The link will stop working after 15 days.
47+
4148
## PARAMETERS
4249

4350
### -Connection
@@ -54,6 +61,20 @@ Accept pipeline input: False
5461
Accept wildcard characters: False
5562
```
5663
64+
### -ExpirationDateTime
65+
The date and time after which the sharing link stops working. A value without a time zone, such as `(Get-Date).AddDays(15)` or `"2026-12-31 18:00"`, is treated as local time. When not specified, the link does not expire unless an expiration policy applies to the tenant or site.
66+
67+
```yaml
68+
Type: DateTime
69+
Parameter Sets: (All)
70+
71+
Required: False
72+
Position: Named
73+
Default value: None
74+
Accept pipeline input: False
75+
Accept wildcard characters: False
76+
```
77+
5778
### -Folder
5879
The folder in the site
5980

‎src/Commands/Security/AddFileUserSharingLink.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using PnP.Core.Model.Security;
22
using PnP.Framework.Utilities;
33
using PnP.PowerShell.Commands.Model.SharePoint;
4+
using System;
45
using System.Collections.Generic;
56
using System.Management.Automation;
67

@@ -19,6 +20,9 @@ public class AddPnPFileUserSharingLink : PnPWebCmdlet
1920
[Parameter(Mandatory = false)]
2021
public ShareType ShareType = ShareType.View;
2122

23+
[Parameter(Mandatory = false)]
24+
public DateTime ExpirationDateTime;
25+
2226
protected override void ExecuteCmdlet()
2327
{
2428
var serverRelativeUrl = string.Empty;
@@ -52,6 +56,11 @@ protected override void ExecuteCmdlet()
5256
Recipients = driveRecipients
5357
};
5458

59+
if (ParameterSpecified(nameof(ExpirationDateTime)))
60+
{
61+
shareLinkRequestOptions.ExpirationDateTime = ExpirationDateTime;
62+
}
63+
5564
var share = file.CreateUserSharingLink(shareLinkRequestOptions);
5665

5766
FileSharingLinkResult fileUserSharingLinkResult = new()

‎src/Commands/Security/AddFolderUserSharingLink.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using PnP.Core.Model.SharePoint;
33
using PnP.PowerShell.Commands.Base.PipeBinds;
44
using PnP.PowerShell.Commands.Model.SharePoint;
5+
using System;
56
using System.Collections.Generic;
67
using System.Management.Automation;
78

@@ -20,6 +21,9 @@ public class AddFolderUserSharingLink : PnPWebCmdlet
2021
[Parameter(Mandatory = false)]
2122
public ShareType ShareType = ShareType.View;
2223

24+
[Parameter(Mandatory = false)]
25+
public DateTime ExpirationDateTime;
26+
2327
protected override void ExecuteCmdlet()
2428
{
2529
var serverRelativeUrl = string.Empty;
@@ -43,6 +47,11 @@ protected override void ExecuteCmdlet()
4347
Type = ShareType
4448
};
4549

50+
if (ParameterSpecified(nameof(ExpirationDateTime)))
51+
{
52+
shareLinkRequestOptions.ExpirationDateTime = ExpirationDateTime;
53+
}
54+
4655
var share = folder.CreateUserSharingLink(shareLinkRequestOptions);
4756

4857
FolderSharingLinkResult folderUserSharingLinkResult = new()

0 commit comments

Comments
 (0)