Mitchell Buchanan
Mitchell Buchanan

Reputation: 11

Azure Office 365 Powershell Authentication data

So I can run this script and get the users personal email and phone number

Get-MsolUser -MaxResults 20000 | select -Expand StrongAuthenticationUserDetails |select  Email, PhoneNumber |Export-Csv C:\Temp\LicensedUsers9.csv

I can get this script to give me the obvious data it requests

Get-MSOLUser -MaxResults 200000  |Select-Object  DisplayName, UserPrincipalName, isLicensed, OtherMails, MobilePhone, PhoneNumber, TelephoneNumber | Export-Csv C:\Temp\LicensedUsers32.csv

I cannot figure out how to get the first script to include the UPN. If I add it all I get is blanks in the cells

My plan for this is to cross reference data to upload for the Office 365 password reset but I want to merge the data and not overwrite what is there

Upvotes: 0

Views: 157

Answers (2)

Mitchell Buchanan
Mitchell Buchanan

Reputation: 11

This worked Get-MsolUser -EnabledFilter EnabledOnly -All | Select UserPrincipalName, DisplayName, MobilePhone, AlternateEmailAddresses, AlternateMobilePhones -ExpandProperty StrongAuthenticationUserDetails | Export-Csv C:\Temp\LicensedUsers321.csv

Upvotes: 1

PowerShellGuy
PowerShellGuy

Reputation: 801

I don't have the requirements for those cmdlets, but I see what's needed.

We need to build a custom property, and use an expression to expand the value of the nested property we want.


Get-MsolUser -MaxResults 20000 |  
    select @{label="Email";expression={$_.StrongAuthenticationUserDetails.Email}}, 
           @{label="PhoneNumber";expression={$_.StrongAuthenticationUserDetails.PhoneNumber}},
           UserPrincipalName  | Export-Csv C:\Temp\LicensedUsers9.csv

What this is doing, is creating custom NoteProperty(s), and adding them to the result of our select statement. The reason we need to do this, is because the value of the StrongAuthenticationUserDetails property is a nested object, most likely a hashtable (though I can't check to be certain), and we want to expand it inline, while grabbing the other non-custom properties at the same time.

Upvotes: 0

Related Questions