TIP – AzureAD Object ids to UserprincipalNames

Sharing a small post with a TIP (small script) that will help many of system administrators that deal with PowerApps and PowerAutomate.

We have got a report from Microsoft for owners of the flows (Powerautomate) that are using HTTP connectors as we want to communicate them that premium license is now required to use this connector.


Issue is report does not contain owners UserPrincipalName but objectids so it is hard to identify who is who.

So, use the simple code in this post to get their UserPrincipalName.

First collect the guids in text file C:\temp\objectids.txt

Prerequisite:

Connect to the module using Connect-MsolService


Now run below code and you will get users UPN values corresponding to the objectids, report will be in csv form and will be saved to path c:\temp\objid2upn.csv.

############################################################

$collection=@()

get-content C:\temp\objectids.txt | ForEach-Object{

$coll = “” | Select Objectid,userprincipalName

$msoluser = get-msoluser -objectid $_.trim() | Select Objectid,userprincipalName

$coll.objectid = $_.trim()

if($msoluser){

$coll.userprincipalName= $msoluser.userprincipalName

}

else{

$coll.userprincipalName = “Not Found”

}

$collection+=$coll

$coll

}

$collection | export-csv c:\temp\objid2upn.csv -notypeinfo

##############################################################

Script is using MSOnline to get the user information in AzureAD based on their objectid and then fetching theirs Userprincipalnames.

Line number 4 is the main code here as that is what is getting the user à
$msoluser = get-msoluser -objectid $_.trim()

You can template this code to get other attributes or use it in some other way that is relevant as per your needs.

 

 

Thanks for reading………….

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s