Add-PnPFileUserSharingLink
SYNOPSIS
Creates a sharing link to share a file with a list of specified users.
SYNTAX
Add-PnPFileUserSharingLink -FileUrl <String> -Users <String[]> [-ShareType <PnP.Core.Model.Security.ShareType>] [-ExpirationDateTime <DateTime>] [-Connection <PnPConnection>]
DESCRIPTION
Creates a new user sharing link for a file.
EXAMPLES
EXAMPLE 1
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Users "john@contoso.onmicrosoft.com","jane@contoso.onmicrosoft.com"
This will create an user sharing link for Test.docx file in the Shared Documents library which will be viewable to specified users in the organization.
EXAMPLE 2
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -ShareType Edit -Users "john@contoso.onmicrosoft.com","jane@contoso.onmicrosoft.com"
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.
EXAMPLE 3
Add-PnPFileUserSharingLink -FileUrl "/sites/demo/Shared Documents/Test.docx" -Users "john@contoso.onmicrosoft.com" -ExpirationDateTime (Get-Date).AddDays(15)
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.
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.
Type: PnPConnection
Parameter Sets: (All)
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ExpirationDateTime
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.
Type: DateTime
Parameter Sets: (All)
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-FileUrl
The file in the site
Type: String
Parameter Sets: (All)
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ShareType
The type of sharing that you want to, i.e do you want to enable people in your organization to view the shared content or also edit the content?
CreateOnly value is not supported.
Type: PnP.Core.Model.Security.ShareType
Parameter Sets: (All)
Required: False
Position: Named
Default value: View
Accept pipeline input: False
Accept wildcard characters: False
-Users
The UPN(s) of the user(s) to with whom you would like to share the file.
Type: String[]
Parameter Sets: (All)
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False