From d92f72736857d4936687f9b1a77676cbeb5dce08 Mon Sep 17 00:00:00 2001 From: "Christian.Rohr" Date: Sat, 11 Mar 2023 20:36:16 +0100 Subject: [PATCH 1/5] Added warning in the catch block --- src/Commands/Files/MoveFile.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Commands/Files/MoveFile.cs b/src/Commands/Files/MoveFile.cs index 4b7b9a5a8..66a41f0c8 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,8 +83,9 @@ protected override void ExecuteCmdlet() var folderServerRelativePath = folder.EnsureProperty(f => f.ServerRelativePath); isFolder = folderServerRelativePath.DecodedUrl == ResourcePath.FromDecodedUrl(TargetUrl).DecodedUrl; } - catch + catch (Exception ex) { + WriteWarning(ex.Message); } if (isFolder) { From 646eb00fa990134b1debd31c516575af0875a079 Mon Sep 17 00:00:00 2001 From: "Christian.Rohr" Date: Sun, 19 Mar 2023 19:22:38 +0100 Subject: [PATCH 2/5] Changed WriteWarning to WriteVerbose --- src/Commands/Files/MoveFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Files/MoveFile.cs b/src/Commands/Files/MoveFile.cs index 66a41f0c8..4f4934c0d 100644 --- a/src/Commands/Files/MoveFile.cs +++ b/src/Commands/Files/MoveFile.cs @@ -85,7 +85,7 @@ protected override void ExecuteCmdlet() } catch (Exception ex) { - WriteWarning(ex.Message); + WriteVerbose(ex.Message); } if (isFolder) { From b38fcac246bbc080efd6dce373cf612e146eb172 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Mon, 20 Mar 2023 12:12:45 +0100 Subject: [PATCH 3/5] Made notion of the Verbose parameter being supported on this cmdlet now --- documentation/Move-PnPFile.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 From 63b38cc7e7d22cd9a383cb3b60b9ccb2ce06d2e4 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Mon, 20 Mar 2023 12:12:53 +0100 Subject: [PATCH 4/5] Added changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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] From aae240190cc2fff4b9db72c0c5818189feb9db0f Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Mon, 20 Mar 2023 12:13:20 +0100 Subject: [PATCH 5/5] Updated code to give context around the verbose message being shown and to also show verbose output on what its doing when things do go well --- src/Commands/Files/MoveFile.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/Files/MoveFile.cs b/src/Commands/Files/MoveFile.cs index 4f4934c0d..fc3b43d47 100644 --- a/src/Commands/Files/MoveFile.cs +++ b/src/Commands/Files/MoveFile.cs @@ -85,22 +85,22 @@ protected override void ExecuteCmdlet() } catch (Exception ex) { - WriteVerbose(ex.Message); + 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)