Asked by:
Set hidefromaddressbook to true for all users in OU

Question
-
I am using this:
Get-ADUser -filter * -searchbase "ou=you,ou=OU..." |
Set-ADUser -replace @{msExchHideFromAddressLists=$true}
I can do it for 1 person, but can do it for all users in the OU. Any ideas?
Thank you
Tuesday, December 10, 2019 9:26 PM
All replies
-
I would suggest:
Get-ADUser -Filter * -SearchBase "ou=you,ou=OU..." | ForEach-Object { Set-ADUser -Identity $_.sAMAccountName -Replace @{msExchHideFromAddressLists=$True} }
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
Tuesday, December 10, 2019 10:34 PM -
The code without a line break would work.
Get-ADUser -filter * -searchbase 'ou=you,ou=OU...' | Set-ADUser -replace @{msExchHideFromAddressLists=$true}
You cannot have a double line break after a "pipe". It will cause an error. YOU can have one line break but you have two.
Get-ADUser -filter * -searchbase 'ou=you,ou=OU...' | Set-ADUser -replace @{msExchHideFromAddressLists=$true}
\_(ツ)_/
- Edited by jrv Tuesday, December 10, 2019 10:41 PM
Tuesday, December 10, 2019 10:40 PM -
Who do people tend to use set-aduser and replace command, instead of using cmdlet which has the parameter to do the job? (Set-Mailbox -hiddenFromAddressListsEnabled:$False, which will also correctly clear showinaddressbook attribute)
Wednesday, December 11, 2019 11:40 AM -
Who do people tend to use set-aduser and replace command, instead of using cmdlet which has the parameter to do the job? (Set-Mailbox -hiddenFromAddressListsEnabled:$False, which will also correctly clear showinaddressbook attribute)
Exchange CmdLets are not necessarily available in all deployments.
\_(ツ)_/
Wednesday, December 11, 2019 6:54 PM -
What would be the most efficient way to ensure the flag is set only on disabled account. Is it to modify get-aduser to only return disabled, or put it in the loop?Friday, December 13, 2019 7:14 PM
-
Would be most efficient to filter on the PowerShell property Enabled. Instead if using "-Filter *", use:
Get-ADUser -Filter {Enabled -eq $False}
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Edited by Richard MuellerMVP Friday, December 13, 2019 7:46 PM corrected
Friday, December 13, 2019 7:43 PM