diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e4451251..d594a5956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Changed ### Fixed +- Using UPNs with an apostrophe in it not working with `Remove-PnPUserProfile`, `Export-PnPUserProfile`, `Export-PnPUserInfo`, and `Remove-PnPUserInfo`. The apostrophe is now escaped in the API request. [#5459](https://github.com/pnp/powershell/pull/5459) ## [3.4.1] @@ -24,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors - Gautam Sheth [gautamdsheth] +- [till-llit] ## [3.4.0] diff --git a/src/Commands/Principals/ExportUserInfo.cs b/src/Commands/Principals/ExportUserInfo.cs index 7f373b00f..230a40358 100644 --- a/src/Commands/Principals/ExportUserInfo.cs +++ b/src/Commands/Principals/ExportUserInfo.cs @@ -32,7 +32,7 @@ protected override void ExecuteCmdlet() var site = Tenant.GetSiteByUrl(siteUrl); AdminContext.Load(site); AdminContext.ExecuteQueryRetry(); - var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}"); + var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''")); var results = RestHelper.Get>(Connection.HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/GetSPUserInformation(accountName=@a,siteId=@b)?@a='{normalizedUserName}'&@b='{site.Id}'", AdminContext, false); var record = new PSObject(); foreach (var item in results.Items) diff --git a/src/Commands/Principals/RemoveUserInfo.cs b/src/Commands/Principals/RemoveUserInfo.cs index bd454564c..9d4e99ccc 100644 --- a/src/Commands/Principals/RemoveUserInfo.cs +++ b/src/Commands/Principals/RemoveUserInfo.cs @@ -35,7 +35,7 @@ protected override void ExecuteCmdlet() var site = Tenant.GetSiteByUrl(siteUrl); AdminContext.Load(site); AdminContext.ExecuteQueryRetry(); - var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}"); + var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''")); RestResultCollection results = null; if (!ParameterSpecified(nameof(RedactName))) { @@ -43,7 +43,8 @@ protected override void ExecuteCmdlet() } else { - results = RestHelper.Post>(HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/RemoveSPUserInformation(accountName=@a,siteId=@b,redactName=@c)?@a='{normalizedUserName}'&@b='{site.Id}'&@c='{RedactName}'", this.AccessToken, false); + var redactName = UrlUtilities.UrlEncode(RedactName.Replace("'", "''")); + results = RestHelper.Post>(HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/RemoveSPUserInformation(accountName=@a,siteId=@b,redactName=@c)?@a='{normalizedUserName}'&@b='{site.Id}'&@c='{redactName}'", this.AccessToken, false); } var record = new PSObject(); foreach (var item in results.Items) diff --git a/src/Commands/UserProfiles/ExportUserProfile.cs b/src/Commands/UserProfiles/ExportUserProfile.cs index 7223942f1..1db77a12c 100644 --- a/src/Commands/UserProfiles/ExportUserProfile.cs +++ b/src/Commands/UserProfiles/ExportUserProfile.cs @@ -20,7 +20,7 @@ protected override void ExecuteCmdlet() { hostUrl = hostUrl.Substring(0, hostUrl.Length - 1); } - var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}"); + var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''")); var results = RestHelper.Get>(Connection.HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/GetUserProfileProperties(accountName=@a)?@a='{normalizedUserName}'", AdminContext, false); var record = new PSObject(); foreach (var item in results.Items) diff --git a/src/Commands/UserProfiles/RemoveUserProfile.cs b/src/Commands/UserProfiles/RemoveUserProfile.cs index 16bcbd960..f095f5b8c 100644 --- a/src/Commands/UserProfiles/RemoveUserProfile.cs +++ b/src/Commands/UserProfiles/RemoveUserProfile.cs @@ -22,7 +22,7 @@ protected override void ExecuteCmdlet() { hostUrl = hostUrl.Substring(0, hostUrl.Length - 1); } - var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}"); + var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''")); if (!ParameterSpecified(nameof(UserId))) {