Script to rename a file in a document library to match the values in the document library columns

Copper Contributor

I'm stuck. I have a document library where files are uploaded with random names. Is it possible to write a script to rename the file when it comes into the document library to match the values in the document library columns? Like "filename-author-time created.pdf" The Sharepoint is on-premise.

any help would be great

4 Replies
Yep, totally possible...you can use CSOM (Client Side Object Model) in PowerShell or PnP cmdlets to do that

Thanks for the positive answer, but would it be possible to maybe point me in a general direction as to how it is actually done with Powershell? Anything would help.

Thanks,
Kentss

Another option is to create an Azure Logic App that triggers on file created.
I have a client using this approach and works fine

 @kentss this could also be done with a flow in Power Automate starting with the SharePoint When a file is created (properties only) trigger.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User