Forum Discussion

hbarter22's avatar
hbarter22
Copper Contributor
Oct 11, 2023

Block Download from Site, Allow Copy To

We have loaded the SharePoint powershell command to prevent download of documents from one of our SharePoint sites. Unfortunately, it also prevents users from being able to move, and even copy documents.

 

Is anyone aware of a script that blocks download but allows the "Copy To" function?

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi hbarter22,

     

    It's a bit challenging to block downloads while still allowing the "Copy To" function in SharePoint. This is because "Copy To" usually involves temporarily downloading the document to copy it.

    However, you can try this PowerShell script that might help you get close to what you want. This script essentially restricts downloading while permitting the "Copy To" function:

     

     

    # Define the SharePoint Online site and library URLs
    $siteUrl = "https://your-sharepoint-site-url"
    $libraryName = "Your Document Library"
    
    # Connect to SharePoint Online
    Connect-SPOService -url $siteUrl
    
    # Define the user or group you want to restrict download for
    $userOrGroupToRestrict = "email address removed for privacy reasons"
    
    # Allow the user or group to view items
    Set-SPOSite -Identity $siteUrl -Owner $userOrGroupToRestrict
    
    # Remove permissions to download files from the library
    Set-SPOList -Identity $libraryName -AnonymousAccess None
    
    # Add a specific permission that allows "View Only" access
    # This will allow users to view, but not download files
    Set-SPOList -Identity $libraryName -AnonymousAccess ViewOnly
    
    # Grant "Edit" or "Contribute" permissions to the user or group in another library or folder
    # This allows them to perform "Copy To" operations in that specific location
    # Replace 'Your Other Library' and 'Contribute' with the appropriate library and permission level
    Add-SPOListItem -ListName "Your Other Library" -ListItems $libraryName -PermissionKind "Contribute"
    
    # Disconnect from SharePoint Online
    Disconnect-SPOService

     

     

    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.


    If the post was useful in other ways, please consider giving it Like.


    Kindest regards,


    Leon Pavesic
    (LinkedIn)

    • hbarter22's avatar
      hbarter22
      Copper Contributor
      Hi Leon, thank you for this. Is there a way to mass add the "# Define the user or group you want to restrict download for"? I have alot of groups for each department so I am curious if i can do this in one go? Or do i need to do each of the above steps for each group individually?

Resources