# Get-AzureADUser Operators

**URL:** <https://forums.powershell.org/t/get-azureaduser-operators/17953>\
**Category:** PowerShell Help\
**Created:** [November 15, 2021, 5:34pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953 "2021-11-15T17:34:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 15, 2021, 5:34pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/1 "2021-11-15T17:34:16Z")

</div>

Hello,

I am trying to query our Azure AD for the presence of domains _other_ than our own (i.e. External guest users).

Examining the UPN of such a User I see “username\_otherDomainName.com#EXT#@ourdomain.com” listed

How can I use Azure AD PowerShell cmdlets to query and list all of them?

I’ve tried using Operators that work in local Powershell but they appear to not work in Azure AD PowerShell.

```auto
Get-AzureADUser -Filter "userPrincipalName -contains 'EXT'" -top 10 

```

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [November 15, 2021, 9:19pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/2 "2021-11-15T21:19:56Z")

</div>

There may be a better way to do this but if you want to use a filter then you should use the `-like` operator. `-contains` is for checking if a value is in a collection.

```auto
Get-AzureADUser -Filter "userPrincipalName -like '*EXT*'" -top 10

```

```auto
$names = @('buffy','willow','giles','spike')
$names -contains 'willow'
$names -contains 'xander'

```

> **[about Operators - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2)**
>
> Describes the operators that are supported by PowerShell.

Edit: actually, checking the docs for this, I remember the Azure cmdlets don’t use the standard syntax. It uses oData filters and if I remember rightly from my testing, only a subset of those filters work. I think you might have to get all the users and filter afterwards with `Where-Object`. Still an Azure newbie I’m afraid so hopefully someone with more experience in AzureAD will correct me if I’m wrong.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 15, 2021, 10:44pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/3 "2021-11-15T22:44:48Z")

</div>

The AzureAD module is very, very restricted compared to the AD modules.

> <https://stackoverflow.com/questions/59547039/searching-for-multiple-strings-in-azure-ad-groups>

You can use -SearchString as a “startswith” type of filter on DisplayName

```auto
# basically startswith(DisplayName,'value')"
Get-AzureADUser -SearchString value

```

For filtering against the userprincipalname, you basically have startswith, eq, and any. If you have the entire userprincipalname, then just use

```auto
Get-AzureADUser -Filter "UserPrincipalName eq '$($input.UserPrincipalName)'"

```

If you have the beginning, use startswith

```auto
Get-AzureADUser -Filter "startswith(UserPrincipalName,'value')"

```

Otherwise you are going to have to filter after the query with Where-Object. Another possible solution I found is

```auto
Get-AzureADDomainNameReference -Name somedomain.com | where {$_.ObjectType -eq "User"}

```

Here’s the weird way you can filter for enabled accounts

```auto
Get-AzureADUser -Filter "Accountenabled eq true"

```

It limits the results to 100 by default and this weird syntax is how you can fix that

```auto
Get-AzureADUser -Filter "Accountenabled eq true" -All $true

```

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 16, 2021, 3:45pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/4 "2021-11-16T15:45:01Z")

</div>

Thanks Doug I did read that earlier but don’t see a way (other than ‘startswith’) to get the string _inside_ the UPN.

krzydoug\_DougsDomain#EXT#@powershell.org

How would I find you and all other 3rd party users/domains in Azure with #EXT# as an unchanging string?

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 17, 2021, 4:40pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/5 "2021-11-17T16:40:06Z")

</div>

I would assume something like this

```auto
Get-AzureADUser -All $true | Where-Object UserPrincipalName -match '#EXT#'

```

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 17, 2021, 6:02pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/6 "2021-11-17T18:02:09Z")

</div>

That returned a whole heckuva lot more users than MS’ supplied query:

```auto
Get-AzureADUser -Filter "UserType eq 'Guest'" 

```

Thank you Doug

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/get-azureaduser-operators/17953/7 "2024-05-16T20:20:25Z")

</div>

Closed on May 16, 2024, 8:20pm UTC


