Skip to content

Commit

Permalink
Added verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
KoenZomers committed Jul 6, 2023
1 parent 4be388c commit a78eb0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
18 changes: 16 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.sharepoin
## SYNTAX

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

## DESCRIPTION
Expand Down Expand Up @@ -93,6 +93,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Verbose
When provided, additional debug statements will be shown while executing the cmdlet.

```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)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
18 changes: 14 additions & 4 deletions src/Commands/UserProfiles/GetUserProfileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ protected override void ExecuteCmdlet()
var peopleManager = new PeopleManager(AdminContext);

// Loop through each of the requested users
foreach (var acc in Account)
foreach (var account in Account)
{
var currentAccount = acc;
var result = Tenant.EncodeClaim(currentAccount);
WriteVerbose($"Getting user profile properties for {account}");
var result = Tenant.EncodeClaim(account);
AdminContext.ExecuteQueryRetry();
currentAccount = result.Value;
var currentAccount = result.Value;

WriteVerbose($"Account {account} encoded to {currentAccount}");

SortedDictionary<string, object> upsDictionary = new();

// Check if specific user profile properties have been requested
if (ParameterSpecified(nameof(Properties)) && Properties != null && Properties.Length > 0 && Properties.All(p => !basicProperties.Contains(p)))
{
// Specific user profile properties have been requested and none of them are basic user profile properties, return only those properties that have been requested
WriteVerbose($"Retrieving {Properties.Length} specific non basic user profile {(Properties.Length != 1 ? "properties" : "property")} for account {currentAccount}");

UserProfilePropertiesForUser userProfilePropertiesForUser = new UserProfilePropertiesForUser(AdminContext, currentAccount, Properties);
var userRequestedProperties = peopleManager.GetUserProfilePropertiesFor(userProfilePropertiesForUser);
AdminContext.Load(userProfilePropertiesForUser);
Expand All @@ -54,13 +58,17 @@ protected override void ExecuteCmdlet()
else
{
// No specific user profile properties have been requested or there were basic user profile properties amongst them
WriteVerbose($"Retrieving all user profile properties for {currentAccount}");

var userProfileProperties = peopleManager.GetPropertiesFor(currentAccount);
AdminContext.Load(userProfileProperties);
AdminContext.ExecuteQueryRetry();

// Check if we only need to output specific properties or all of them
if (ParameterSpecified(nameof(Properties)) && Properties != null && Properties.Length > 0)
{
WriteVerbose($"Adding specific {Properties.Length} user profile {(Properties.Length != 1 ? "properties" : "property")} to the output");

// Check if any of the base user profile properties have been requested and if so, add them to the output as well
if (Properties.Contains("AccountName")) upsDictionary.Add("AccountName", userProfileProperties.AccountName);
if (Properties.Contains("DirectReports")) upsDictionary.Add("DirectReports", userProfileProperties.DirectReports);
Expand Down Expand Up @@ -101,6 +109,8 @@ protected override void ExecuteCmdlet()
else
{
// Add all of the basic user profile properties to the output
WriteVerbose("Adding all user profile properties to the output");

upsDictionary.Add("AccountName", userProfileProperties.AccountName);
upsDictionary.Add("DirectReports", userProfileProperties.DirectReports);
upsDictionary.Add("DisplayName", userProfileProperties.DisplayName);
Expand Down

0 comments on commit a78eb0f

Please sign in to comment.