Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding upload entire local folder to SharePoint Online into Copy-PnPFolder #3850

Merged
merged 9 commits into from
Apr 8, 2024
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-UseVersionExpirationReport` parameter to `Get-PnPFileVersion` cmdlet to get the version expiration report for a single file. [#3799](https://github.com/pnp/powershell/pull/3799)
- Added `-DelayDenyAddAndCustomizePagesEnforcement` parameter to `Set-PnPTenant` cmdlet which allows delay of the change to custom script set on the Tenant until mid-November 2024. [#3815](https://github.com/pnp/powershell/pull/3815)
- Added additional permissions for Graph application permission validate sets. [#3835](https://github.com/pnp/powershell/issues/3835)
- Added `LoopDefaultSharingLinkRole`, `DefaultShareLinkScope`, `DefaultShareLinkRole`, `LoopDefaultSharingLinkScope` and `DefaultLinkToExistingAccessReset` parameters to `Set-PnPTenant` cmdlet
- Added the ability to upload entire local folders with files and optionally subfolders to SharePoint Online into 'Copy-PnPFolder' [#3850](https://github.com/pnp/powershell/pull/3850)
- Added `LoopDefaultSharingLinkRole`, `DefaultShareLinkScope`, `DefaultShareLinkRole`, `LoopDefaultSharingLinkScope` and `DefaultLinkToExistingAccessReset` parameters to `Set-PnPTenant` cmdlet. [#3874](https://github.com/pnp/powershell/pull/3874)

### Fixed

Expand Down
74 changes: 67 additions & 7 deletions documentation/Copy-PnPFolder.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@ title: Copy-PnPFolder
# Copy-PnPFolder

## SYNOPSIS
Copies a folder or file to a different location
Copies a folder or file to a different location within SharePoint Online or allows uploading of an entire local folder with optionally subfolders to SharePoint Online.

## SYNTAX

### Copy files within Microsoft 365

```powershell
Copy-PnPFolder -SourceUrl <String> -TargetUrl <String> [-Overwrite] [-Force] [-IgnoreVersionHistory] [-NoWait] [-Connection <PnPConnection>] [-Verbose]

```

### Copy files from local to Microsoft 365

```powershell
Copy-PnPFolder [-SourceUrl] <String> [-TargetUrl] <String> [-Overwrite] [-Force] [-IgnoreVersionHistory] [-NoWait] [-Connection <PnPConnection>]
Copy-PnPFolder -LocalPath <String> -TargetUrl <String> [-Overwrite] [-Recurse] [-RemoveAfterCopy] [-Connection <PnPConnection>] [-Verbose]

```

## DESCRIPTION

Copies a folder or file to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name.
Copies a folder or file to a different location within SharePoiint. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name.

Copying files and folders is bound to some restrictions. You can find more on it here: https://learn.microsoft.com/office365/servicedescriptions/sharepoint-online-service-description/sharepoint-online-limits#moving-and-copying-across-sites

It can also accommodate copying an entire folder with all its files and optionally even subfolders and files from a local path onto SharePoint Online.

## EXAMPLES

### EXAMPLE 1
Expand Down Expand Up @@ -109,14 +120,21 @@ if($jobStatus.JobState == 0)

Copies a file named company.docx from the current document library to the documents library in SubSite2. It will not wait for the action to return but returns job information instead. The Receive-PnPCopyMoveJobStatus cmdlet will return the job status.

### EXAMPLE 12
```powershell
Copy-PnPFolder -LocalPath "c:\temp" -TargetUrl "Subsite1/Shared Documents" -Recurse -Overwrite
```

Copies all the files and underlying folders from the local folder c:\temp to the document library Shared Documents in Subsite1. If a file already exists, it will be overwritten.

## PARAMETERS

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

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Parameter Sets: WITHINM365

Required: False
Position: Named
Expand All @@ -130,7 +148,7 @@ If provided, only the latest version of the document will be copied and its hist

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Parameter Sets: WITHINM365

Required: False
Position: Named
Expand All @@ -140,7 +158,7 @@ Accept wildcard characters: False
```

### -Overwrite
If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the copy operation will be canceled if the file already exists at the TargetUrl location.
If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the copy operation will be canceled if the file already exists at the TargetUrl location when copying between two locations on SharePoint Online. If copying files from a local path to SharePoint Online, it will skip any file that already exists and still continue with the next one.

```yaml
Type: SwitchParameter
Expand All @@ -158,7 +176,7 @@ Site or server relative URL specifying the file or folder to copy. Must include

```yaml
Type: String
Parameter Sets: (All)
Parameter Sets: WITHINM365
Aliases: SiteRelativeUrl, ServerRelativeUrl

Required: True
Expand Down Expand Up @@ -186,6 +204,48 @@ Accept wildcard characters: False
### -NoWait
If specified the task will return immediately after creating the copy job. The cmdlet will return a job object which can be used with Receive-PnPCopyMoveJobStatus to retrieve the status of the job.

```yaml
Type: SwitchParameter
Parameter Sets: WITHINM365

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

### -Recurse
When copying files from a local folder to SharePoint Online, this parameter will copy all files and folders within the local folder and all of its subfolders as well.

```yaml
Type: SwitchParameter
Parameter Sets: FROMLOCAL

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

### -RemoveAfterCopy
When copying files from a local folder to SharePoint Online, this parameter will remove all files locally that have successfully been uploaded to SharePoint Online. If a file fails, it will not be removed locally. Local folders will be removed after all files have been uploaded and the folder is empty.

```yaml
Type: SwitchParameter
Parameter Sets: FROMLOCAL

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

### -Verbose
When provided, additional debug statements will be shown while executing the cmdlet.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Expand Down
1 change: 0 additions & 1 deletion src/Commands/Files/CopyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace PnP.PowerShell.Commands.Files
{
[Alias("Copy-PnPFolder")]
[Cmdlet(VerbsCommon.Copy, "PnPFile")]
public class CopyFile : PnPWebCmdlet
{
Expand Down
Loading
Loading