|
| 1 | +--- |
| 2 | +Module Name: PnP.PowerShell |
| 3 | +schema: 2.0.0 |
| 4 | +applicable: SharePoint Online |
| 5 | +online version: https://pnp.github.io/powershell/cmdlets/Copy-PnPFileMetadata.html |
| 6 | +external help file: PnP.PowerShell.dll-Help.xml |
| 7 | +title: Copy-PnPFileMetadata |
| 8 | +--- |
| 9 | + |
| 10 | +# Copy-PnPFileMetadata |
| 11 | + |
| 12 | +## SYNOPSIS |
| 13 | + |
| 14 | +Synchronizes metadata between files and folders in SharePoint |
| 15 | + |
| 16 | +## SYNTAX |
| 17 | + |
| 18 | +```powershell |
| 19 | +Copy-PnPFileMetadata [-SourceUrl] <String> [-TargetUrl] <String> [-Fields <String[]>] [-Recursive] [-Force] [-Connection <PnPConnection>] [-SourceConnection <PnPConnection>] [-TargetConnection <PnPConnection>] |
| 20 | +``` |
| 21 | + |
| 22 | +## DESCRIPTION |
| 23 | + |
| 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. |
| 25 | + |
| 26 | +When updating items, the cmdlet uses `UpdateOverwriteVersion()` to allow setting system fields while avoiding new user-facing versions. |
| 27 | + |
| 28 | +For folder contents, files are processed one-by-one. |
| 29 | + |
| 30 | +## EXAMPLES |
| 31 | + |
| 32 | +### EXAMPLE 1 |
| 33 | + |
| 34 | +```powershell |
| 35 | +Copy-PnPFileMetadata -SourceUrl "Shared Documents/MyProject" -TargetUrl "/sites/target/Shared Documents/MyProject" |
| 36 | +``` |
| 37 | + |
| 38 | +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. |
| 39 | + |
| 40 | +### EXAMPLE 2 |
| 41 | + |
| 42 | +```powershell |
| 43 | +Copy-PnPFileMetadata -SourceUrl "Shared Documents/report.docx" -TargetUrl "/sites/archive/Documents/report.docx" |
| 44 | +``` |
| 45 | + |
| 46 | +Synchronizes metadata for a single file from the source to the target, restoring the original system fields. |
| 47 | + |
| 48 | +### EXAMPLE 3 |
| 49 | + |
| 50 | +```powershell |
| 51 | +Copy-PnPFileMetadata -SourceUrl "Shared Documents/Projects" -TargetUrl "/sites/backup/Documents/Projects" -Fields @("Created", "Modified") -Force |
| 52 | +``` |
| 53 | + |
| 54 | +Synchronizes only the Created and Modified dates for the Projects folder and its contents, without prompting for confirmation. |
| 55 | + |
| 56 | +### EXAMPLE 4 |
| 57 | + |
| 58 | +```powershell |
| 59 | +Copy-PnPFileMetadata -SourceUrl "Shared Documents/Archives" -TargetUrl "/sites/newsite/Documents/Archives" -Recursive:$false |
| 60 | +``` |
| 61 | + |
| 62 | +Synchronizes metadata only for the Archives folder itself, without processing its subfolders and files. |
| 63 | + |
| 64 | +### EXAMPLE 5 |
| 65 | + |
| 66 | +```powershell |
| 67 | +$src = Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/archives -ReturnConnection |
| 68 | +$dst = Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/projects -ReturnConnection |
| 69 | +Copy-PnPFileMetadata -SourceUrl "Shared Documents/MyProject" -TargetUrl "Shared Documents/MyProject" -SourceConnection $src -TargetConnection $dst -Verbose |
| 70 | +``` |
| 71 | + |
| 72 | +Synchronizes metadata across two different site connections. |
| 73 | + |
| 74 | +## PARAMETERS |
| 75 | + |
| 76 | +### -Force |
| 77 | + |
| 78 | +If provided, no confirmation will be requested and the action will be performed |
| 79 | + |
| 80 | +```yaml |
| 81 | +Type: SwitchParameter |
| 82 | +Parameter Sets: (All) |
| 83 | + |
| 84 | +Required: False |
| 85 | +Position: Named |
| 86 | +Default value: None |
| 87 | +Accept pipeline input: False |
| 88 | +Accept wildcard characters: False |
| 89 | +``` |
| 90 | +
|
| 91 | +### -Fields |
| 92 | +
|
| 93 | +Specifies which metadata fields to synchronize. Default fields are Created, Modified, Author, and Editor. |
| 94 | +
|
| 95 | +```yaml |
| 96 | +Type: String[] |
| 97 | +Parameter Sets: (All) |
| 98 | + |
| 99 | +Required: False |
| 100 | +Position: Named |
| 101 | +Default value: @("Created", "Modified", "Author", "Editor") |
| 102 | +Accept pipeline input: False |
| 103 | +Accept wildcard characters: False |
| 104 | +``` |
| 105 | +
|
| 106 | +### -Recursive |
| 107 | +
|
| 108 | +If provided, processes folders recursively including all subfolders and files. This is enabled by default. |
| 109 | +
|
| 110 | +```yaml |
| 111 | +Type: SwitchParameter |
| 112 | +Parameter Sets: (All) |
| 113 | + |
| 114 | +Required: False |
| 115 | +Position: Named |
| 116 | +Default value: $true |
| 117 | +Accept pipeline input: False |
| 118 | +Accept wildcard characters: False |
| 119 | +``` |
| 120 | +
|
| 121 | +
|
| 122 | +
|
| 123 | +### -SourceUrl |
| 124 | +
|
| 125 | +Site or server relative URL specifying the file or folder to copy metadata from. Must include the file name if it is a file or the entire path to the folder if it is a folder. |
| 126 | +
|
| 127 | +```yaml |
| 128 | +Type: String |
| 129 | +Parameter Sets: (All) |
| 130 | +Aliases: ServerRelativeUrl |
| 131 | + |
| 132 | +Required: True |
| 133 | +Position: 0 |
| 134 | +Default value: None |
| 135 | +Accept pipeline input: True (ByValue) |
| 136 | +Accept wildcard characters: False |
| 137 | +``` |
| 138 | +
|
| 139 | +### -TargetUrl |
| 140 | +
|
| 141 | +Site or server relative URL specifying the file or folder to copy metadata to. Must include the file name if it is a file or the entire path to the folder if it is a folder. |
| 142 | +
|
| 143 | +```yaml |
| 144 | +Type: String |
| 145 | +Parameter Sets: (All) |
| 146 | +Aliases: TargetServerRelativeUrl |
| 147 | + |
| 148 | +Required: True |
| 149 | +Position: 1 |
| 150 | +Default value: None |
| 151 | +Accept pipeline input: False |
| 152 | +Accept wildcard characters: False |
| 153 | +``` |
| 154 | +
|
| 155 | +### -SourceConnection |
| 156 | +
|
| 157 | +Optional connection to be used for accessing the source file or folder. If not provided, the current connection is used. |
| 158 | +
|
| 159 | +```yaml |
| 160 | +Type: PnPConnection |
| 161 | +Parameter Sets: (All) |
| 162 | + |
| 163 | +Required: False |
| 164 | +Position: Named |
| 165 | +Default value: None |
| 166 | +Accept pipeline input: False |
| 167 | +Accept wildcard characters: False |
| 168 | +``` |
| 169 | +
|
| 170 | +### -TargetConnection |
| 171 | +
|
| 172 | +Optional connection to be used for accessing the target file or folder. If not provided, the current connection is used. |
| 173 | +
|
| 174 | +```yaml |
| 175 | +Type: PnPConnection |
| 176 | +Parameter Sets: (All) |
| 177 | + |
| 178 | +Required: False |
| 179 | +Position: Named |
| 180 | +Default value: None |
| 181 | +Accept pipeline input: False |
| 182 | +Accept wildcard characters: False |
| 183 | +``` |
| 184 | +
|
| 185 | +## RELATED LINKS |
| 186 | +
|
| 187 | +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
0 commit comments