Skip to main content

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 is fail.

--bypassSharedLock

This 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 is full.

--query [query]

JMESPath query string. See http://jmespath.org/ for more information and examples.

-o, --output [output]

Output type. json, text, csv, md. Default json.

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Remarks

info

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:

  • fail will throw an error when the destination file already exists.
  • replace will replace the destination file if it already exists.
  • rename will 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

CTRL + M