Aug 29 2016 04:48 AM - edited Aug 29 2016 04:51 AM
How to rename a document/file stored inside a documentlibrary using Office Dev PnP? I haven't found a cmdlet for it.
Specifically I want to rename the OneNote Notebook called "Team Site Notebook" that's generated for each team site to a name which corresponds to the site title, e.g. "{SiteTitle} Notebook".
If that's not possible, the alternative solution would be to create a new OneNote Notebook which corresponds to the site title, e.g. "{SiteTitle} Notebook". If you have a solution for that, that's also great.
Aug 29 2016 10:42 PM
Aug 30 2016 09:35 AM
SolutionI might be misinterpreting the question, but does this help?
"MoveTo" can be used to rename files.
Connect-SPOnline -url [yoururl] $ctx = Get-SPOContext $web = Get-SPOWeb $file = $web.GetFileByServerRelativeUrl("[your file url]") $file.MoveTo("[your NEW server-relative url]", 'Overwrite') $ctx.ExecuteQuery()
Aug 31 2016 04:39 AM
I was just surprised that there is not a cmdlet inside the Office Dev PnP library, e.g. Rename-SPOFile($SourceFileName, $DestinationFileName) method, or Move-SPOFile($SourceFileName, $DestinationFileName).
Thanks @Deleted and @Charles Willwerth for the solutions.
I'm now using the SharePoint Online CSOM based solution of Charles to realize the business requirement.
Aug 31 2016 04:46 AM
Sep 01 2016 07:57 PM
Sep 02 2016 02:09 AM
You are right @Douglas Ware.
@Charles Willwerth pointed me in the right direction. I was aware about a OneNote Notebook being a folder instead of an item, so I've realised it with this code:
$ctx = Get-SPOContext $web = Get-SPOWeb $folder = $web.GetFolderByServerRelativeUrl("/sites/SITEURL/SiteAssets/Team Site Notebook") $folder.MoveTo("/sites/SITEURL/SiteAssets/MySpecificSiteNotebookName") $ctx.ExecuteQuery()
Aug 30 2016 09:35 AM
SolutionI might be misinterpreting the question, but does this help?
"MoveTo" can be used to rename files.
Connect-SPOnline -url [yoururl] $ctx = Get-SPOContext $web = Get-SPOWeb $file = $web.GetFileByServerRelativeUrl("[your file url]") $file.MoveTo("[your NEW server-relative url]", 'Overwrite') $ctx.ExecuteQuery()