spo file copy
Copies a file to another location
Usage
m365 spo file copy [options]
Options
-u, --webUrl <webUrl>The URL of the site where the file is located.
-s, --sourceUrl <sourceUrl>Site-relative, server-relative or absolute URL of the file.
-t, --targetUrl <targetUrl>Server-relative or absolute URL of the location.
--newName [newName]New name of the destination file.
--nameConflictBehavior [nameConflictBehavior]Behavior when a document with the same name is already present at the destination. Possible values:
fail,replace,rename. Default isfail.--bypassSharedLockThis indicates whether a file with a share lock can still be copied. Use this option to copy a file that is locked.
-h, --help [help]Output usage information. Optionally, specify which section of command's help you want to see. Allowed values are
options,examples,remarks,response,full. Default isfull.--query [query]JMESPath query string. See http://jmespath.org/ for more information and examples.
-o, --output [output]Output type.
json,text,csv,md. Defaultjson.--verboseRuns command with verbose logging.
--debugRuns command with debug logging.
Remarks
The required URLs webUrl, sourceUrl and targetUrl cannot be encoded. When you do so, you will get a File Not Found error.
When you specify a value for nameConflictBehavior, consider the following:
failwill throw an error when the destination file already exists.replacewill replace the destination file if it already exists.renamewill add a suffix (e.g. Document1.pdf) when the destination file already exists.
Examples
Copy a file to a document library in another site collection with server relative URLs
m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "/sites/project/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents"
Copy a file to a document library in another site collection with absolute URLs
m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "https://contoso.sharepoint.com/sites/project/Shared Documents/Document.pdf" --targetUrl "https://contoso.sharepoint.com/sites/IT/Shared Documents"
Copy file to a document library in another site collection with a new name
m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "/sites/project/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents" --newName "Report.pdf"
Copy file to a document library in another site collection with a new name, rename the file if it already exists
m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "/sites/project/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents" --newName "Report.pdf" --nameConflictBehavior rename
More information
- Copy items from a SharePoint document library: https://support.office.com/en-us/article/move-or-copy-items-from-a-sharepoint-document-library-00e2f483-4df3-46be-a861-1f5f0c1a87bc