diff --git a/CHANGELOG.md b/CHANGELOG.md index cb2ffb8aa..6693f5d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-OpenDocumentsMode` option to `Set-PnPList` which allows configuring if documents should be opened in the browser or in the local client [#2873](https://github.com/pnp/powershell/pull/2873) - Added `-Properties` parameter to `Get-PnPUserProfileProperty` cmdlet which allows retrieval of specific properties if specified. [#2840](https://github.com/pnp/powershell/pull/2840) - Added support for specifying the `-ContentUrl` configuration in `Add-PnPTeamsTab` cmdlet when trying to add a Planner as a tab in Teams channel. [#2850](https://github.com/pnp/powershell/pull/2850) +- Added support for `-Verbose` in `Move-PnPFile` which will show if it has problems determining if the destination location is a folder or a file [#2888](https://github.com/pnp/powershell/pull/2888) ### Changed @@ -95,6 +96,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors +- Chris R. [ChrisRo89] - Aimery Thomas [a1mery] - Ganesh Sanap [ganesh-sanap] - Markus Hanisch [m-hanisch] diff --git a/documentation/Move-PnPFile.md b/documentation/Move-PnPFile.md index a909e6940..e5ce15c6e 100644 --- a/documentation/Move-PnPFile.md +++ b/documentation/Move-PnPFile.md @@ -15,7 +15,7 @@ Moves a file or folder to a different location ## SYNTAX ```powershell -Move-PnPFile [-SourceUrl] [-TargetUrl] [-Overwrite] [-AllowSchemaMismatch] [-AllowSmallerVersionLimitOnDestination] [-IgnoreVersionHistory] [-NoWait] [-Force] [-Connection ] +Move-PnPFile [-SourceUrl] [-TargetUrl] [-Overwrite] [-AllowSchemaMismatch] [-AllowSmallerVersionLimitOnDestination] [-IgnoreVersionHistory] [-NoWait] [-Force] [-Connection ] [-Verbose] ``` ## DESCRIPTION @@ -193,7 +193,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` -## RELATED LINKS +### -Verbose +When provided, additional debug statements might be shown while executing the cmdlet. -[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) +```yaml +Type: SwitchParameter +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## RELATED LINKS +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/src/Commands/Files/MoveFile.cs b/src/Commands/Files/MoveFile.cs index 4b7b9a5a8..fc3b43d47 100644 --- a/src/Commands/Files/MoveFile.cs +++ b/src/Commands/Files/MoveFile.cs @@ -13,7 +13,7 @@ public class MoveFile : PnPWebCmdlet private const string ParameterSet_SERVER = "Server Relative"; private const string ParameterSet_SITE = "Site Relative"; private const string ParameterSet_OTHERSITE = "Other Site Collection"; - + [Parameter(Mandatory = true)] [Alias("ServerRelativeUrl", "SiteRelativeUrl")] public string SourceUrl = string.Empty; @@ -38,7 +38,7 @@ public class MoveFile : PnPWebCmdlet [Parameter(Mandatory = false)] public SwitchParameter Force; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false)] public SwitchParameter NoWait; protected override void ExecuteCmdlet() @@ -64,9 +64,9 @@ protected override void ExecuteCmdlet() Uri currentContextUri = new Uri(ClientContext.Url); Uri sourceUri = new Uri(currentContextUri, EncodePath(sourceFolder)); - Uri sourceWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri); + Uri sourceWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri); Uri targetUri = new Uri(currentContextUri, EncodePath(targetFolder)); - Uri targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + Uri targetWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); if (Force || ShouldContinue(string.Format(Resources.MoveFile0To1, SourceUrl, TargetUrl), Resources.Confirm)) { @@ -83,23 +83,24 @@ protected override void ExecuteCmdlet() var folderServerRelativePath = folder.EnsureProperty(f => f.ServerRelativePath); isFolder = folderServerRelativePath.DecodedUrl == ResourcePath.FromDecodedUrl(TargetUrl).DecodedUrl; } - catch + catch (Exception ex) { + WriteVerbose($"Error occurred while trying to check if the target URL {TargetUrl} is a folder. This could happen if the target folder does not exist yet. It may still work well. Exception: {ex.Message}"); } if (isFolder) { + WriteVerbose($"Moving file or folder from {sourceUri} to {targetUri}"); Move(currentContextUri, sourceUri, targetUri, SourceUrl, TargetUrl, true); } else { - + WriteVerbose($"Moving file or folder from {SourceUrl} to {TargetUrl}"); var file = CurrentWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(SourceUrl)); file.MoveToUsingPath(ResourcePath.FromDecodedUrl(TargetUrl), Overwrite ? MoveOperations.Overwrite : MoveOperations.None); ClientContext.ExecuteQueryRetry(); } } } - } private string EncodePath(string path)