diff --git a/CHANGELOG.md b/CHANGELOG.md index 77004bf88..c008fd1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-UserAssignedManagedIdentityAzureResourceId` and `-UserAssignedManagedIdentityClientId` as alternatives to `-UserAssignedManagedIdentityObjectId` for `Connect-PnPOnline -ManagedIdentity` to provide an user managed identity to authenticate with. [#2813](https://github.com/pnp/powershell/pull/2813) - Added clearer error message when connecting using an expired client secret and trying to execute a command.[#2828](https://github.com/pnp/powershell/pull/2828) - Added `Undo-PnPFileCheckedOut` which allows a checked out file to discard its changes and revert to the last checked in version. [#2837](https://github.com/pnp/powershell/pull/2837) -- Added support for specifying the `-ContentUrl` configuration in `Add-PnPTeamsTab` cmdlet when trying to add a Planner as a tab in Teams channel. +- 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) ### Changed @@ -61,6 +62,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Properties of `Get-PnPAzureADServicePrincipal` are now all typed instead of some of them returning unparsed JSON fragments. [#2717](https://github.com/pnp/powershell/pull/2717) - Changed `Add-PnPTeamsChannel` to no longer require an `-OwnerUPN` to be provided when specifying `-ChannelType Standard` [#2786](https://github.com/pnp/powershell/pull/2786) - Changed `Add-PnPFile` by default to upload a file as a draft with a minor version now instead of publishing it as a major version. `-CheckinType MajorCheckIn` can be used to still upload the file as a major published version [#2806](https://github.com/pnp/powershell/pull/2806) +- Changed `Get-PnPUserProfileProperty` to no longer return additional user profile properties under UserProfileProperties but instead directly on the returned instance. [#2840](https://github.com/pnp/powershell/pull/2840) ### Removed diff --git a/MIGRATE-1.0-to-2.0.md b/MIGRATE-1.0-to-2.0.md index b81b13b8e..868921851 100644 --- a/MIGRATE-1.0-to-2.0.md +++ b/MIGRATE-1.0-to-2.0.md @@ -73,6 +73,7 @@ Using PnP PowerShell in Azure functions ? You might be required to change the Pn | Add-PnPTeamsChannel | Private | ChannelType | The parameter was obsolete and hence removed. Use `-ChannelType` instead | | New-PnPTeamsTeam | Owner | Owners | The parameter was obsolete and hence removed. Use `-Owners` instead which supports setting multiple owner of a Teams team | | Export-PnPTaxonomy | - | - | The cmdlet does not support export of taxonomy using `UTF-7` encoding. If `UTF-7` is specified, it will switch to `UTF-8` encoding | +| Get-PnPUserProfileProperty | - | - | Additional user profile properties are no longer returned under UserProfileProperties but instead will be directly under the returned instance | ## Other notable changes @@ -87,3 +88,4 @@ Using PnP PowerShell in Azure functions ? You might be required to change the Pn - The output type of `Get-PnPAzureADGroupMember` has changed to `PnP.PowerShell.Commands.Model.Microsoft365User` - The output type of `Get-PnPAzureADGroup` has changed to `PnP.PowerShell.Commands.Model.Graph.Group` - The output type of `New-PnPAzureADGroup` has changed to `PnP.PowerShell.Commands.Model.Graph.Group` +- The output type of `Get-PnPUserProfileProperty` has changed to `SortedDictionary` \ No newline at end of file diff --git a/documentation/Get-PnPUserProfileProperty.md b/documentation/Get-PnPUserProfileProperty.md index 5b30de97a..d94a794a6 100644 --- a/documentation/Get-PnPUserProfileProperty.md +++ b/documentation/Get-PnPUserProfileProperty.md @@ -20,7 +20,7 @@ You must connect to the tenant admin website (https://:-admin.sharepoint ## SYNTAX ```powershell -Get-PnPUserProfileProperty [-Account] [-Connection ] [] +Get-PnPUserProfileProperty -Account [-Properties ] [-Connection ] ``` ## DESCRIPTION @@ -42,6 +42,13 @@ Get-PnPUserProfileProperty -Account 'user@domain.com','user2@domain.com' Returns the profile properties for the specified users +### EXAMPLE 3 +```powershell +Get-PnPUserProfileProperty -Account 'user@domain.com' -Properties 'FirstName','LastName' +``` + +Returns the FirstName and LastName profile properties for the specified user + ## PARAMETERS ### -Account @@ -58,6 +65,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Properties +The user profile properties that are requested for the user e.g. FirstName, LastName etc. + +```yaml +Type: String[] +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Connection Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. @@ -75,4 +96,3 @@ Accept wildcard characters: False ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - diff --git a/src/Commands/UserProfiles/GetUserProfileProperty.cs b/src/Commands/UserProfiles/GetUserProfileProperty.cs index 4f4ebf03e..efd710337 100644 --- a/src/Commands/UserProfiles/GetUserProfileProperty.cs +++ b/src/Commands/UserProfiles/GetUserProfileProperty.cs @@ -1,4 +1,6 @@ -using System.Management.Automation; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.UserProfiles; @@ -7,12 +9,15 @@ namespace PnP.PowerShell.Commands.UserProfiles { [Cmdlet(VerbsCommon.Get, "PnPUserProfileProperty")] - [OutputType(typeof(PersonProperties))] + [OutputType(typeof(SortedDictionary))] public class GetUserProfileProperty : PnPAdminCmdlet { [Parameter(Mandatory = true, Position = 0)] public string[] Account; + [Parameter(Mandatory = false)] + public string[] Properties; + protected override void ExecuteCmdlet() { var peopleManager = new PeopleManager(ClientContext); @@ -24,10 +29,63 @@ protected override void ExecuteCmdlet() ClientContext.ExecuteQueryRetry(); currentAccount = result.Value; - var properties = peopleManager.GetPropertiesFor(currentAccount); - ClientContext.Load(properties); - ClientContext.ExecuteQueryRetry(); - WriteObject(properties); + SortedDictionary upsDictionary = new(); + + if (ParameterSpecified(nameof(Properties)) && Properties != null && Properties.Length > 0) + { + UserProfilePropertiesForUser userProfilePropertiesForUser = new UserProfilePropertiesForUser(ClientContext, currentAccount, Properties); + var userRequestedProperties = peopleManager.GetUserProfilePropertiesFor(userProfilePropertiesForUser); + ClientContext.Load(userProfilePropertiesForUser); + ClientContext.ExecuteQueryRetry(); + + for (var i = 0; i < userRequestedProperties.Count(); i++) + { + object propertyValue = userRequestedProperties.ElementAt(i); + upsDictionary.Add(Properties[i], propertyValue); + } + + WriteObject(upsDictionary, true); + + } + else + { + var userProfileProperties = peopleManager.GetPropertiesFor(currentAccount); + ClientContext.Load(userProfileProperties); + ClientContext.ExecuteQueryRetry(); + + upsDictionary.Add("AccountName", userProfileProperties.AccountName); + upsDictionary.Add("DirectReports", userProfileProperties.DirectReports); + upsDictionary.Add("DisplayName", userProfileProperties.DisplayName); + upsDictionary.Add("Email", userProfileProperties.Email); + upsDictionary.Add("ExtendedManagers", userProfileProperties.ExtendedManagers); + upsDictionary.Add("ExtendedReports", userProfileProperties.ExtendedReports); + upsDictionary.Add("IsFollowed", userProfileProperties.IsFollowed); + upsDictionary.Add("LatestPost", userProfileProperties.LatestPost); + upsDictionary.Add("Peers", userProfileProperties.Peers); + upsDictionary.Add("PersonalSiteHostUrl", userProfileProperties.PersonalSiteHostUrl); + upsDictionary.Add("PersonalUrl", userProfileProperties.PersonalUrl); + upsDictionary.Add("PictureUrl", userProfileProperties.PictureUrl); + upsDictionary.Add("Title", userProfileProperties.Title); + upsDictionary.Add("UserUrl", userProfileProperties.UserUrl); + + if (userProfileProperties.UserProfileProperties != null && userProfileProperties.UserProfileProperties.Count > 0) + { + for (var i = 0; i < userProfileProperties.UserProfileProperties.Count; i++) + { + var element = userProfileProperties.UserProfileProperties.ElementAt(i); + if (!upsDictionary.ContainsKey(element.Key)) + { + upsDictionary.Add(element.Key, element.Value); + } + else + { + upsDictionary[element.Key] = element.Value; + } + } + } + + WriteObject(upsDictionary, true); + } } } }