Rename-PnPFile

Renames a file in its current location

Syntax

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

Examples

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

PS:>Rename-PnPFile -ServerRelativeUrl /sites/project/Documents/company.docx -TargetFileName mycompany.docx

Renames a file named company.docx located in the document library called Documents located in the projects sitecollection under the managed path sites to mycompany.docx. If a file named mycompany.aspx already exists, it won't perform the rename.

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

PS:>Rename-PnPFile -SiteRelativeUrl Documents/company.aspx -TargetFileName mycompany.docx

Renames a file named company.docx located in the document library called Documents located in the current site to mycompany.aspx. If a file named mycompany.aspx already exists, it won't perform the rename.

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

PS:>Rename-PnPFile -ServerRelativeUrl /sites/project/Documents/company.docx -TargetFileName mycompany.docx -OverwriteIfAlreadyExists

Renames a file named company.docx located in the document library called Documents located in the projects sitecollection under the managed path sites to mycompany.aspx. If a file named mycompany.aspx already exists, it will still perform the rename and replace the original mycompany.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 exist with the provided TargetFileName, it will be overwritten. If omitted, the rename operation will be canceled if a file already exists with the TargetFileName file name.

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

Server relative Url specifying the file to rename. 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 rename. Must include the file name.

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

File name to rename the file to. Should only be the file name and not include the path to its location. Use Move-PnPFile to move the file to another location.

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