none
Hidden from GAL

    Question

  • Hello.


    I'm working on a script to change "msExchHideFromAddressLists" attribute automatically for disables users in a specific OU.


    $ou = " ""--"" "
    Get-ADUser -SearchBase $ou -Filter * -Properties * | foreach {Set-adUser $_ -Add @{msExchHideFromAddressLists="TRUE"}}


    But I receive an error.  Where I have mistaken? 

    Wednesday, May 22, 2019 11:05 AM

All replies


  • Please format your code as code using the code posting tool provided on the icon bar of the post editor (second to last icon). Thanks

    But I receive an error. 

    What's the error? Please post the complete error message (formatted as code as well, please)

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 22, 2019 12:26 PM
  • $ou = "OU=()Disabled,OU=2,DC=1,DC=local"
    Get-ADUser -SearchBase $ou -Filter * -Properties * | foreach {Set-adUser $_ -Add @{msExchHideFromAddressLists="TRUE"}}

    and recive that: 

    Set-adUser : Multiple values were specified for an attribute that can have only 
    one value
    At line:2 char:63
    + ... * | foreach {Set-adUser $_ -Add @{msExchHideFromAddressLists="TRUE"}}
    +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=Dan ,...=1,DC=local:ADU 
       ser) [Set-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:8321,Microsoft.ActiveDirectory 
       .Management.Commands.SetADUser


    • Edited by KlausMorgan Wednesday, May 22, 2019 1:11 PM
    Wednesday, May 22, 2019 1:09 PM
  • Hi, 

    You may use -Replace instead -Add

    Wednesday, May 22, 2019 1:23 PM
  • Too many mistakes and too much code:

    $ou = 'OU=()Disabled,OU=2,DC=1,DC=local'
    Get-ADUser -SearchBase $ou -Filter * | 
        Set-adUser -Replace @{ msExchHideFromAddressLists = $true }

    Don't superstitiously add items to code without understanding what they do.  Take some time to learn the basics of PowerShell and you will save a lot of time.

    NEVER use the strings "TRUE/FALSE" for a Boolean.  You must use either "$true/$false" or the numbers 1/0.  Never place quotes around a Boolean.

    The string "FALSE" is $true.

    To test:

    [bool]'FALSE'

    which will always evaluate to $true.


    \_(ツ)_/


    • Edited by jrvModerator Wednesday, May 22, 2019 1:45 PM
    • Proposed as answer by BOfH_666 Wednesday, May 22, 2019 1:48 PM
    Wednesday, May 22, 2019 1:41 PM
    Moderator
  • I always rather use Exchange cmdlets for setting these attributes

    set-mailbox accountname -HiddenFromAddressListsEnabled $true

    Wednesday, May 22, 2019 2:43 PM
  • Yes, but i want to do it automatically and ou based. 
    Thursday, May 23, 2019 6:13 AM
  • Get-ADUser -filter * -searchbase "OU=()Disabled,OU=2,DC=1,DC=local" | 
    	Set-ADUser -replace @{msExchHideFromAddressLists=$true}

    Did that. 

    tnx. 
    Thursday, May 23, 2019 6:22 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Lee

    Just do it.

    Thursday, May 23, 2019 7:13 AM
    Moderator
  • Then use Get-Mailbox and pipe the results to Set-Mailbox. Why not use the tools designed to work with the objects you're working with?

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, May 23, 2019 3:07 PM