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 decoded URL of the file. Specify either sourceUrl or sourceId but not both.

-i, --sourceId [sourceId]

The Unique ID (GUID) of the file. Specify either sourceUrl or sourceId but not both.

-t, --targetUrl <targetUrl>

Server-relative or absolute decoded 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. Allowed values: fail, replace, rename. Defaults to fail.

--resetAuthorAndCreated

Use this option to clear the author and created date. When not specified, the values from the source file are used.

--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 options.

--query [query]

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

-o, --output [output]

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

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Remarks

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 by server-relative URL to a document library in another site collection with server relative URL.

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 by site-relative URL to a document library in another site collection and clear the author and created date.

m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceUrl "/Shared Documents/Document.pdf" --targetUrl "/sites/IT/Shared Documents" --resetAuthorAndCreated

Copy file by sourceId (UniqueId) to a document library in another site collection and rename the file.

m365 spo file copy --webUrl https://contoso.sharepoint.com/sites/project --sourceId "b2307a39-e878-458b-bc90-03bc578531d6" --targetUrl "/sites/IT/Shared Documents" --newName "Report.pdf"

Copy file by sourceId (UniqueId) 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 --sourceId "b2307a39-e878-458b-bc90-03bc578531d6" --targetUrl "/sites/IT/Shared Documents" --newName "Report.pdf" --nameConflictBehavior rename

Response

The command won't return a response on success.

More information

CTRL + M