Rename-PnPFile

Tip

We encourage you to make improvements to this documentation. Please navigate to https://github.com/pnp/powershell/blob/dev/documentation/Rename-PnPFile.md to change this file.

Renames a file in its current location

Syntax

Rename-PnPFile
      [-ServerRelativeUrl] <String>
      [-TargetFileName] <String>
      [-OverwriteIfAlreadyExists]
      [-Force]
      [-Connection <PnPConnection>]  
      [<CommonParameters>]
Rename-PnPFile
      [-SiteRelativeUrl] <String>
      [-TargetFileName] <String>
      [-OverwriteIfAlreadyExists]
      [-Force]
      [-Connection <PnPConnection>]  
      [<CommonParameters>]

Examples

EXAMPLE 1

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

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

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:PnPConnection
Position:Named
Default value:None
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
Default value:None
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
Default value:None
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
Default value:None
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
Default value:None
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
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False