Get-MgUserAuthenticationMethod--unable to extract additional values

Hi All,

When using Get-MgUserAuthenticationMethod I’m unalbe to extreact additional values…See below for the context…


Get-MgUserAuthenticationMethod -UserId $user22   | Get-Member  -MemberType Properties


   TypeName: Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuthenticationMethod

Name                 MemberType Definition                                                                              
----                 ---------- ----------                                                                              
AdditionalProperties Property   System.Collections.Generic.IDictionary[string,System.Object] AdditionalProperties {get;}
Id                   Property   string Id {get;set;}
Get-MgUserAuthenticationMethod -UserId $user22 |select AdditionalProperties  ## This Works!!!

AdditionalProperties                                                                                                                                                 
--------------------                                                                                                                                                 
{[@odata.type, #microsoft.graph.passwordAuthenticationMethod]}                                                                                                       
{[@odata.type, #microsoft.graph.microsoftAuthenticatorAuthenticationMethod], [displayName, iPhone 13], [deviceTag, SoftwareTokenActivated], [phoneAppVersion, 6.6.8]}

##This works but I want to more finite extractions

$(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties 

Key             Value                                                      
---             -----                                                      
@odata.type     #microsoft.graph.passwordAuthenticationMethod              
@odata.type     #microsoft.graph.microsoftAuthenticatorAuthenticationMethod
displayName     iPhone 13                                                  
deviceTag       SoftwareTokenActivated                                     
phoneAppVersion 6.6.8

*//THIS does not work\*


$(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties | Select DisplayName

DisplayName
-----------

///GOAL\\

I want to extract these additional values " DispayName, devicetag & SoftwareTokenActivated).

What is the proper snytax to extract this valies in a FL or FT output…?

Thanks in Advance

albert,
Welcome to the forum. :wave:t4:

Without having experiences with this topic or access to an Azure tenant …

It looks like these properties are provided as hashtable. So you should be able to access the values with their key name.

(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.displayName
#or
(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.deviceTag

Olaf,

Excellent, thx for the advice & guidance for a beginner…


(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.displayName
iPhone 13

(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.deviceTag
SoftwareTokenActivated

(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.phoneAppVersion
6.6.8

Is there any optimal way to re-write the above three (3) PS cmdlet into a one-line that prints all three key names via one PS cmdlet…?

I tried this below via ExpandProperty , and got NULL results…


Get-MgUserAuthenticationMethod -UserId $user22 -ExpandProperty $odata.type  | Select @{Name = 'DisplayName'; Expression = {$_.$odata.type.AdditionalProperties.displayName}} ## EMPTY DATA!!!!

DisplayName
-----------

Thanks in advance

Hi
Powershell is object language.
You have to learn what
“command | Get-Member” show to you
and what expandproperty is doing with your object.
Try with some simple commands like get-process etc.
Good Luck :slight_smile:

Use getenumerator method to drill through the hashtable then filter the key name with where object.

(Get-MgUserAuthenticationMethod -UserId $user22).AdditionalProperties.GetEnumerator() |
    Where-Object {$_.key -eq 'displayName' -or $_.key -eq 'deviceTag' -or $_.key -eq 'phoneAppVersion'} 

i’m not sure how to use select object with hashtable maybe someone can advice?