Skip to content

Commit 88e25d8

Browse files
committed
CopyFileMetadata: improve performance, and reduce server load
1 parent dfa563e commit 88e25d8

File tree

2 files changed

+396
-309
lines changed

2 files changed

+396
-309
lines changed

documentation/Copy-PnPFileMetadata.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,49 @@ Copy-PnPFileMetadata [-SourceUrl] <String> [-TargetUrl] <String> [-Fields <Strin
2121

2222
## DESCRIPTION
2323

24-
Synchronizes metadata (Created, Modified, Author, Editor) from source files and folders to their corresponding targets without copying the actual content. This cmdlet is particularly useful for restoring lost metadata after migration operations where system fields may have been reset.
24+
Synchronizes metadata (Created, Modified, Author, Editor) from source files and folders to their corresponding targets without copying the actual content. This cmdlet is useful for restoring lost metadata after migrations where system fields may have been reset.
2525

2626
When updating items, the cmdlet uses `UpdateOverwriteVersion()` to allow setting system fields while avoiding new user-facing versions.
2727

28-
For folder contents, files are processed one-by-one.
28+
For folders, the cmdlet batches updates per folder to reduce round-trips and improve performance on large libraries. With `-Verbose`, it logs progress for each folder and file processed, including periodic batch flush messages.
29+
30+
Both `-SourceUrl` and `-TargetUrl` can be provided as absolute URLs, server-relative (starting with `/`), or web-relative paths. URLs are normalized against their respective connections: the source URL is normalized using `-SourceConnection` (or the current connection), and the target URL is normalized using `-TargetConnection` (or the current connection). Targets must already exist; if a corresponding target file or folder is not found, it is skipped.
2931

3032
## EXAMPLES
3133

32-
### EXAMPLE 1
34+
### EXAMPLE 1 (same site, folder, recursive)
3335

3436
```powershell
35-
Copy-PnPFileMetadata -SourceUrl "Shared Documents/MyProject" -TargetUrl "/sites/target/Shared Documents/MyProject"
37+
Copy-PnPFileMetadata -SourceUrl "Shared Documents/MyProject" -TargetUrl "Shared Documents/MyProject"
3638
```
3739

3840
Synchronizes metadata for the MyProject folder and all its contents recursively from the source to the target location, preserving original creation dates, modification dates, and author information.
3941

40-
### EXAMPLE 2
42+
### EXAMPLE 2 (same site, single file)
4143

4244
```powershell
43-
Copy-PnPFileMetadata -SourceUrl "Shared Documents/report.docx" -TargetUrl "/sites/archive/Documents/report.docx"
45+
Copy-PnPFileMetadata -SourceUrl "Shared Documents/report.docx" -TargetUrl "Shared Documents/report.docx"
4446
```
4547

4648
Synchronizes metadata for a single file from the source to the target, restoring the original system fields.
4749

48-
### EXAMPLE 3
50+
### EXAMPLE 3 (same site, limited fields)
4951

5052
```powershell
51-
Copy-PnPFileMetadata -SourceUrl "Shared Documents/Projects" -TargetUrl "/sites/backup/Documents/Projects" -Fields @("Created", "Modified") -Force
53+
Copy-PnPFileMetadata -SourceUrl "Shared Documents/Projects" -TargetUrl "Shared Documents/Projects" -Fields @("Created", "Modified") -Force
5254
```
5355

5456
Synchronizes only the Created and Modified dates for the Projects folder and its contents, without prompting for confirmation.
5557

56-
### EXAMPLE 4
58+
### EXAMPLE 4 (same site, non-recursive)
5759

5860
```powershell
59-
Copy-PnPFileMetadata -SourceUrl "Shared Documents/Archives" -TargetUrl "/sites/newsite/Documents/Archives" -Recursive:$false
61+
Copy-PnPFileMetadata -SourceUrl "Shared Documents/Archives" -TargetUrl "Shared Documents/Archives" -Recursive:$false
6062
```
6163

6264
Synchronizes metadata only for the Archives folder itself, without processing its subfolders and files.
6365

64-
### EXAMPLE 5
66+
### EXAMPLE 5 (cross site, two connections)
6567

6668
```powershell
6769
$src = Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/archives -ReturnConnection
@@ -98,7 +100,7 @@ Parameter Sets: (All)
98100

99101
Required: False
100102
Position: Named
101-
Default value: @("Created", "Modified", "Author", "Editor")
103+
Default value: @("Author", "Editor", "Created", "Modified")
102104
Accept pipeline input: False
103105
Accept wildcard characters: False
104106
```

0 commit comments

Comments
 (0)