Skip to content
Merged
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions MIGRATE-1.0-to-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<string, object>`
24 changes: 22 additions & 2 deletions documentation/Get-PnPUserProfileProperty.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You must connect to the tenant admin website (https://:<tenant>-admin.sharepoint
## SYNTAX

```powershell
Get-PnPUserProfileProperty [-Account] <String[]> [-Connection <PnPConnection>] [<CommonParameters>]
Get-PnPUserProfileProperty -Account <String[]> [-Properties <String[]>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand All @@ -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
Expand All @@ -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.

Expand All @@ -75,4 +96,3 @@ Accept wildcard characters: False
## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

70 changes: 64 additions & 6 deletions src/Commands/UserProfiles/GetUserProfileProperty.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -7,12 +9,15 @@
namespace PnP.PowerShell.Commands.UserProfiles
{
[Cmdlet(VerbsCommon.Get, "PnPUserProfileProperty")]
[OutputType(typeof(PersonProperties))]
[OutputType(typeof(SortedDictionary<string, object>))]
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);
Expand All @@ -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<string, object> 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);
}
}
}
}
Expand Down