Skip to content

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

Open
@ThePoShWolf

Description

@ThePoShWolf

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions