Device name that associate with User Principal Name

Ahmed Alshatawi 235 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 Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Intune | Other
{count} votes

1 answer

Sort by: Most helpful
  1. ZhoumingDuan-MSFT 17,345 Reputation points Microsoft External Staff
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.