Reputation: 81
I am trying to execute the below command in PowerShell by passing my email ID in the command and it does not return anything.
$objectid = (Get-AzureRmADUser -Mail "<your email id>").Id
Is there any alternate solution?
Upvotes: 1
Views: 798
Reputation: 1069
I just tested this on my own Tenant and it works just fine.
The only case where it did not work was when the Mail did not match any valid Mail address, then I simply got nothing returned.
First off to make sure you are not encountering a bug, make sure you have updated your AzureRM Module
Update-Module AzureRM
Else I would suggest that you try using the UserPrincipalName as a test to see if you can get it working with the UserPrincipalName as the identifier instead.
By this I mean, still use the -Mail
property, but for the value, use the users UserPrincipalName instead of the email address.
Also make sure that the email address you are trying to find is not an Alias, most of these commands only works with whatever primary mail addresses attribute is put into the mail field and not any proxy addresses.
For alternative solutions if the AzureRM module just doesn't work for you, you could try the AzureAD Module instead
Install-Module AzureAD
This module has the Get-AzureADUser
cmdlet which can also provide the object ID of the Azure AD user.
To find a user based on Mail from the Get-AzureADUser
cmdlet, use the -Filter
property.
Get-AzureADUser -Filter "Mail eq '[email protected]'"
If this does not work. Try just running (Get-AzureADUser).mail
to get a list of all mail addresses and validate that the one you expect to find is actually on the list, just to make 100% sure that the mail you are expecting to find actually is as a value on a user object.
Upvotes: 3