Device name that associate with User Principal Name

Ahmed Alshatawi 100 Reputation points
2024-09-25T14:00:48.28+00:00

Hello,

I have a CSV list of 450 AzureAD users (userPrincipalName), is there anyway or script to get the machines ObjectID or host names for these 400 users that are currently use\login please?

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,081 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,811 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ZhoumingDuan-MSFT 13,075 Reputation points Microsoft Vendor
    2024-09-26T06:52:48.37+00:00

    @Ahmed Alshatawi,Thanks for posting in Q&A.

    Based on my research, here is script temple you can refer.

    Install-Module -Name AzureAD

    Connect-AzureAD

    $computers = Import-Csv -Path "your csv file path"

    $objectids = foreach ($computer in $computers) { Get-AzureADDevice -All $true -SearchString "$($computer.userprincipalName)" | select ObjectID }

    $objectids | Export-csv -Path "output csv file path" -NoTypeInformation

    In the command at line ($objectids), make sure the userprincipalName matches the column heading in your CSV file

    Or based on my research, here are some links with useful methods you can refer.

    https://techlabs.blog/categories/azure/get-azure-ad-device-object-id-from-computer-display-name-using-powershell

    https://stackoverflow.com/questions/69860566/get-bulk-aad-user-objects-directory-object-from-list-of-upn-submitted-to-graph

    https://stackoverflow.com/questions/69835775/in-powershell-get-upn-from-pc-name

    Non-official, just for reference.

    Hope above information can help you.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.