Exchange Management Shell Filter users based on an existing attribute

Chris Martinez 21 Reputation points
2022-10-03T21:00:33.82+00:00

In Exchange Management Shell I run these commands to try to set a couple of users remote powershell access to disabled:

$DSA = Get-User -ResultSize Unlimited -Filter "(RecipientType -eq 'UserMailbox') -and (Title -like 'Sales Associate')"

$DSA | foreach {Set-User -Identity $_ -RemotePowerShellEnabled $false}

After I input the 2nd command, I get this response from the shell:
cmdlet Set-User at command pipeline position 1
Supply values for the following parameters:
Identity:

I am not sure what I am supposed to do. I got the instructions from control-remote-powershell-access-to-exchange-servers and it does not mention this part.

Exchange Exchange Server Management
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-10-03T21:26:02.037+00:00

    You can't use the user object as the identity. You can, however, use a property of the user object:

    $DSA | foreach {Set-User -Identity $_.distinguishedname -RemotePowerShellEnabled $false}  
    

    Because you already have an array of user objects in the $DSA variable, using a pipeline is less efficient than using a simple "foreach" statement:

    foreach ($u in $DSA){Set-User -Identity $u.distinguishedname -RemotePowerShellEnabled $false}  
    

    If you prefer to use a pipeline (and avoid the overhead of creating an intermediate array just to one time), then this is better:

    Get-User -ResultSize Unlimited -Filter "(RecipientType -eq 'UserMailbox') -and (Title -like 'Sales Associate')" |  
        foreach-object {Set-User -Identity $_.distinguishedname -RemotePowerShellEnabled $false}  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. KyleXu-MSFT 26,396 Reputation points
    2022-10-04T02:05:49.563+00:00

    @Chris Martinez

    Run command blow first, make sure it could find the correct users on your Exchange server:

    $DSA = Get-User -ResultSize Unlimited -Filter "(RecipientType -eq 'UserMailbox') -and (Title -like '*Sales Associate*')"  
    $DSA   
    

    If there doesn't exist output, it means the filer that you used isn't correct. You need to modify the filter first.

    Here is an example in my lab:
    247217-1.png

    Please note, there exist * in the command. You also need to pay attention to the Space between the $_ and -RemotePowerShellEnabled.


    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 Answers by the question author, which helps users to know the answer solved the author's problem.