Table of contents
TOC
Collapse the table of content
Expand the table of content

Rename-PnPFile

Bert Jansen|Last Updated: 2/20/2017
|
1 Contributor

Renames a file in its current location

Syntax

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

Parameters

ParameterTypeRequiredDescription
ServerRelativeUrlStringTrueServer relative Url specifying the file to rename. Must include the file name.
SiteRelativeUrlStringTrueSite relative Url specifying the file to rename. Must include the file name.
TargetFileNameStringTrueFile 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.
ForceSwitchParameterFalseIf provided, no confirmation will be requested and the action will be performed
OverwriteIfAlreadyExistsSwitchParameterFalseIf provided, if a file already exist with the provided TargetFileName, it will be overwritten. If ommitted, the rename operation will be canceled if a file already exists with the TargetFileName file name.
WebWebPipeBindFalseThe web to apply the command to. Omit this parameter to use the current web.

Examples

Example 1

PS:>Move-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:>Move-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:>Move-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.

© 2017 Microsoft