spo file move
Moves a file to another location
Usage
m365 spo file move [options]
Options
-u, --webUrl <webUrl>
The URL of the site where the file is located.
-s, --sourceUrl [sourceUrl]
The server-, site-relative or absolute decoded URL of the file to move. Specify either
sourceUrl
orsourceId
but not both.-i, --sourceId [sourceId]
The ID of the file to move. Specify either
sourceUrl
orsourceId
but not both.-t, --targetUrl <targetUrl>
Server-relative or absolute decoded URL where to move the file.
--newName [newName]
The new name of the destination file.
--nameConflictBehavior [nameConflictBehavior]
Behavior when a file or folder with the same name is already present at the destination. Possible values:
fail
,replace
,rename
. The default isfail
.--retainEditorAndModified
Use this option to retain the editor and modified date. When not specified, these values are reset when moving to another library.
--bypassSharedLock
This indicates whether a file with a share lock can still be moved. Use this option to move 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 isoptions
.--query [query]
JMESPath query string. See http://jmespath.org/ for more information and examples.
-o, --output [output]
Output type.
json
,text
,csv
,md
,none
. Defaultjson
.--verbose
Runs command with verbose logging.
--debug
Runs command with debug logging.
Remarks
All file versions are retained while moving a file.
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
Move a file to a document library in another site collection by server relative URL
m365 spo file move --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl "/sites/project-x/Shared Documents/sp1.pdf" --targetUrl "/sites/project-y/Archived documents"
Move a file specified by a server-relative URL to a document library and rename it
m365 spo file move --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl "/Shared Documents/sp1.pdf" --targetUrl "/sites/project-x/My Documents" --newName Report.pdf
Move a file to another document library and replace a file with the same name
m365 spo file move --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl "/Shared Documents/Report project-x.pdf" --targetUrl "/sites/project-x/My Documents" --newName Report.pdf --nameConflictBehavior replace
Move a file referenced by its ID to another document library and retain editor and modified date
m365 spo file move --webUrl https://contoso.sharepoint.com/sites/project-x --sourceId b8cc341b-9c11-4f2d-aa2b-0ce9c18bcba2 --targetUrl "/sites/project-x/My Documents" --retainEditorAndModified
Response
The command won't return a response on success.
More information
- Move 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