Move-PnPFile

Moves a file to a different location

Syntax

Move-PnPFile
    -ServerRelativeUrl <String>
                -TargetUrl <String>
                [-OverwriteIfAlreadyExists [<SwitchParameter>]]
                [-Force [<SwitchParameter>]]
                [-Web <WebPipeBind>]
                [-Connection <SPOnlineConnection>]
Move-PnPFile
    -SiteRelativeUrl <String>
                -TargetUrl <String>
                [-OverwriteIfAlreadyExists [<SwitchParameter>]]
                [-Force [<SwitchParameter>]]
                [-Web <WebPipeBind>]
                [-Connection <SPOnlineConnection>]

Examples

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

PS:>Move-PnPFile -ServerRelativeUrl /sites/project/Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx

Moves a file named company.docx located in the document library called Documents located in the projects sitecollection under the managed path sites to the site collection otherproject located in the managed path sites. If a file named company.aspx already exists, it won't perform the move.

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

PS:>Move-PnPFile -SiteRelativeUrl Documents/company.aspx -TargetUrl /sites/otherproject/Documents/company.docx

Moves a file named company.docx located in the document library called Documents located in the current site to the Documents library in the site collection otherproject located in the managed path sites. If a file named company.aspx already exists, it won't perform the move.

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

PS:>Move-PnPFile -ServerRelativeUrl /sites/project/Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx -OverwriteIfAlreadyExists

Moves a file named company.docx located in the document library called Documents located in the projects sitecollection under the managed path sites to the site collection otherproject located in the managed path sites. If a file named company.aspx already exists, it will still perform the move and replace the original company.aspx file.

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 move 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
-ServerRelativeUrl

Server relative Url specifying the file to move. Must include the file name.

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

Site relative Url specifying the file to move. Must include the file name.

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

Server relative Url where to move the file to. Must include the file name.

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