PowerShell to get User Principal Name that associate with Device name

Ahmed Alshatawi 235 Reputation points
2024-10-24T01:32:46.2933333+00:00

Hello,

I have a CSV file that have 400 device names from Entra ID, I want to get the User Principal Namethat associate with device name. Is there a PowerShell script to get the UPN from the device name in Entra? Thanks.

Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2024-10-27T15:54:48.5966667+00:00

    Try something like this:

    Import-CSV blabla.csv | select -ExpandProperty DisplayName | % { Get-MgDevice -Filter "displayName eq '$_'" -ExpandProperty registeredOwners | select @{n="DeviceName";e={$_.DisplayName}},@{n="Owner";e={$_.RegisteredOwners[0].AdditionalProperties.userPrincipalName}} }
    

    where the CSV file must have a column DisplayName to designate the device.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.