Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering block throwing errors for Entra commands #732

Open
SteveMutungi254 opened this issue Apr 23, 2024 · 6 comments
Open

Filtering block throwing errors for Entra commands #732

SteveMutungi254 opened this issue Apr 23, 2024 · 6 comments
Assignees
Labels
PM For PM desk ToTriage

Comments

@SteveMutungi254
Copy link
Contributor

SteveMutungi254 commented Apr 23, 2024

Customer feedback:

Error: Get-EntraUser: Cannot evaluate parameter 'Filter' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input.

Example:

PS C:\Program Files\PowerShell\Modules> get-entrauser -Filter {mail eq 'user@contoso'} | select-object userprincipalname
Get-EntraUser: Cannot evaluate parameter 'Filter' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input.

Working example:

PS C:\Program Files\PowerShell\Modules> get-entrauser -Filter "mail eq '[email protected]'" | select-object userprincipalname

UserPrincipalName
----
[email protected]

Microsoft Graph PowerShell cmdlet example:

PS C:\Program Files\PowerShell\Modules> get-mguser -filter {mail eq '[email protected]'} -property userprincipalname | select-object userprincipalname

UserPrincipalName
----
user@contoso

Contributor: @brvr-esko

@alexandair
Copy link
Collaborator

What is the issue here?

-Filter parameter accepts a string value not a script block.

Get-MgUser
 [-ExpandProperty <String[]>]
 [-Property <String[]>] 
[-Filter <String>]
...
...

@brvr-esko
Copy link

Hello, the issue is standardization. I'm not clear why it would work with get-mguser and not with get-entrauser. Having no standardization will make it harder to port existing code to the new entra graph module. Using a scriptblock works with get-aduser and get-mguser, so I would expect it to work with get-entrauser as well.

@snehalkotwal
Copy link
Collaborator

@SteveMutungi254 Thanks for raising the bug we are looking into it.

@alexandair
Copy link
Collaborator

There is no standard in PowerShell to make a parameter that expects a string to work with a script block.

# this works
PS> Get-Service -Name winrm
# this fails
PS> Get-Service -Name {winrm}
Get-Service: Cannot evaluate parameter 'Name' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input.

It's true that Get-MgUser and Get-AzAdUser work when you pass the script block to the -Filter parameter, but Get-AzureAdUser doesn't.
Get-AzureAdUser gives you the same error as Get-EntraUser.

@KenitoInc KenitoInc added the PM For PM desk label Apr 29, 2024
@SteveMutungi254
Copy link
Contributor Author

Hello, @brvr-esko. We recognize the importance of standardization and are committed to maintaining as much consistency as possible.

However, our primary goal is to adopt a forward-looking approach, prioritizing alignment with Microsoft Graph platform standards. While we strive to ensure backward compatibility with older modules like AzureAD, our focus on a forward-looking posture will take precedence.

cc: @alexandair.

@alexandair
Copy link
Collaborator

@SteveMutungi254 @brvr-esko

After some research...

It's all about delay-bind script blocks:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_script_blocks?view=powershell-7.4#using-delay-bind-script-blocks-with-parameters

-Filter parameter for Get-AzADUser and Get-MgUser doesn't accept a pipeline input, that's why script block is just converted to string and cmdlets work.

-Filter parameter for Get-AzureADUser and Get-EntraUser DOES ACCEPT pipeline input and delay-bind script blocks. However, input is not coming through the pipeline, so cmdlets fail with the error: "Cannot evaluate parameter 'Filter' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input."

That's the reason why:
Get-AzADUser -Filter {...} works
Get-MgUser -Filter {...} works
Get-AzureADUser -Filter {...} fails
Get-EntraUser -Filter {...} fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PM For PM desk ToTriage
Projects
None yet
Development

No branches or pull requests

5 participants