Copy-PnPFile

Copies a file or folder to a different location, currently there is a 200MB file size limit for the file to be copied.

Syntax

Copy-PnPFile
    -SourceUrl <String>
                -TargetUrl <String>
                [-OverwriteIfAlreadyExists [<SwitchParameter>]]
                [-Force [<SwitchParameter>]]
                [-SkipSourceFolderName [<SwitchParameter>]]
                [-Web <WebPipeBind>]
                [-Connection <SPOnlineConnection>]

Examples

------------------EXAMPLE 1------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx

Copies a file named company.docx located in a document library called Documents in the current site to the site collection otherproject. If a file named company.docx already exists, it won't perform the copy.

------------------EXAMPLE 2------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Documents/company2.docx

Copies a file named company.docx located in a document library called Documents to a new document named company2.docx in the same library.

------------------EXAMPLE 3------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Documents2/company.docx

Copies a file named company.docx located in a document library called Documents to a document library called Documents2 in the same site.

------------------EXAMPLE 4------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Subsite/Documents/company2.docx

Copies a file named company.docx located in a document library called Documents to the document library named Document in a subsite named Subsite as a new document named company2.docx.

------------------EXAMPLE 5------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Subsite/Documents

Copies a file named company.docx located in a document library called Documents to the document library named Document in a subsite named Subsite keeping the file name.

------------------EXAMPLE 6------------------

PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx -OverwriteIfAlreadyExists

Copies a file named company.docx located in a document library called Documents in the current site to the site collection otherproject. If a file named company.docx already exists, it will still perform the copy and replace the original company.docx file.

------------------EXAMPLE 7------------------

PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents -OverwriteIfAlreadyExists

Copies a folder named MyDocs in the document library called Documents located in the current site to the site collection otherproject. If the MyDocs folder exist it will copy into it, if not it will be created.

------------------EXAMPLE 8------------------

PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents -SkipSourceFolderName -OverwriteIfAlreadyExists

Copies a folder named MyDocs in the document library called Documents located in the current site to the root folder of the library named Documents in the site collection otherproject.

------------------EXAMPLE 9------------------

PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents/MyDocs -SkipSourceFolderName -OverwriteIfAlreadyExists

Copies a folder named MyDocs in the MyDocs folder of the library named Documents. If the MyDocs folder does not exists, it will be created.

------------------EXAMPLE 10------------------

PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents/MyDocs -OverwriteIfAlreadyExists

Copies a folder named MyDocs in the root of the library named Documents. If the MyDocs folder exists in the target, a subfolder also named MyDocs is created.

------------------EXAMPLE 11------------------

PS:>Copy-PnPFile -SourceUrl SubSite1/Documents/company.docx -TargetUrl SubSite2/Documents

Copies a file named company.docx in the library named Documents in SubSite1 to the library named Documents in SubSite2.

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:SPOnlineConnection
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Force

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

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-OverwriteIfAlreadyExists

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.

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-SkipSourceFolderName

If the source is a folder, the source folder name will not be created, only the contents within it.

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-SourceUrl

Site relative Url specifying the file or folder to copy.

Type:String
Aliases:SiteRelativeUrl
Position:0
Accept pipeline input:True
Accept wildcard characters:False
-TargetUrl

Server relative Url where to copy the file or folder to.

Type:String
Position:1
Accept pipeline input:False
Accept wildcard characters:False
-Web

This parameter allows you to optionally apply the cmdlet action to a subweb within the current web. In most situations this parameter is not required and you can connect to the subweb using Connect-PnPOnline instead. Specify the GUID, server relative url (i.e. /sites/team1) or web instance of the web to apply the command to. Omit this parameter to use the current web.

Type:WebPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False