microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Quality of life suggestion on Get-Mg* cmdlets that use $select

Open
#470 4 comments 2 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

enhancement PM: Review Request: Feature
Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

Personally, I like how the ActiveDirectory cmdlets operate when it comes to returning certain attributes. By default there is a minimal set of attributes returned and when a property is passed to the -Properties parameter, that property is added to the existing minimal set of properties.

As an example, if I run:

Get-ADUser ThePoShWolf

The return would look something like:

DistinguishedName : CN=Anthony Howell,DC=domain,DC=com
Enabled           : True
GivenName         : Anthony
Name              : Anthony Howell
ObjectClass       : user
ObjectGUID        : <guid>
SamAccountName    : theposhwolf
SID               : <sid>
Surname           : Howell
UserPrincipalName : theposhwolf@domain.com

If I then run:

Get-ADUser ThePoShWolf -Properties Title

It would return:

DistinguishedName : CN=Anthony Howell,DC=domain,DC=com
Enabled           : True
GivenName         : Anthony
Name              : Anthony Howell
ObjectClass       : user
ObjectGUID        : <guid>
SamAccountName    : theposhwolf
SID               : <sid>
Surname           : Howell
Title             : Powershell Dude
UserPrincipalName : theposhwolf@domain.com

If I look at the Graph module, specifically Get-MgUser, it operates a bit differently. If I pass a property to -Properties, only that property is returned:

Get-MgUser -UserId ThePoShWolf@domain.com -Property Department
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------

I understand that this is how the API operates, but I think it would be extremely useful to be able select properties to add to the default as well as the existing function of exclusivity.

Maybe rename the current -Property feature to -Select and when -Property is used, add the property to the default set of properties that are returned. So if -Select is used, only return the passed properties, but if -Property is used, pass a $select array to the API that includes the default properties and adds whatever is passed to them. So take this command, for example:

Get-MgUser -UserId theposhwolf@domain.com -Property Departmet

With my suggestion, I would expect this to pass the following to the API:

GET /v1.0/users/theposhwolf%40domain.com?$Select=businessPhones%2CdisplayName%2CgivenName%2Cid%2CjobTitle%2Cmail%2CmobilePhone%2CofficeLocation%2CpreferredLanguage%2Csurname%2CuserPrincipalName%2CDepartment

The default list of properties is pulled from https://docs.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#optional-query-parameters.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.