Link to home
Start Free TrialLog in
Avatar of Andy Andy
Andy AndyFlag for India

asked on

Hide External contact

Hello Team,

Please suggest, how can i hide bulk External contact in Exchange 2013 using Powershell..
i have with me external SMTP address which is set currently. Not sure, which attribute we need to take for all user and put in CSV

Suggest the command or script

Thanks,
Andy
Avatar of Andy
Andy

Hi,
You can use the:
Set-MailContact -Identity user@mydomain.com -HiddenFromAddressListsEnabled $true
command to hide these as in this link:
https://robiulislam.wordpress.com/2015/06/25/hide-external-contact-from-office-365-gal/

So, place the e-mail address in a csv then read this in via a script to set them all as hidden.

Something like:
ForEach ($user in $(Get-Content C:\temp\users.txt)) 
{
	Set-MailContact -Identity $user -HiddenFromAddressListsEnabled $true 
}

Open in new window

Avatar of Andy Andy

ASKER

how to check what this script will do and but not initiate it on any contact.. and also we need a output file also, once the script is completed when finally we need to run it
Just test it on one user in the csv initially

What output would you require?
To export all the contacts into a csv. file use following commanr

Get-MailContact -ResultSize Unlimited | Export-Csv C:\Contacts.csv

Then use below command in powershell to hide contacts available on contacts.csv file.

Import-Csv "C:\contacts.csv" | Foreach {get-mailcontact -identity $_.Contacts -Hiddenfromaddresslistenabled $true}
For output

Export a list for contacts hidden from GAL by running the following cmdlet:

Command:
Get-Mailcontact -Filter {HiddenFromAddressListsEnabled -eq $true} | Select identity,alias,HiddenFromAddressListsEnabled | Export-Csv -Path C:\HiddenContacts.csv -NoTypeInformation
output i need in .txt file like what is the result of the script
Andy also confirm, is this correct as per your first comment to initiate it

in script folder where CSV is saved

set-adserversettings -viewentireforest:$true
import-csv hide.csv | foreach {

   set-mailcontact -identity $_.PrimarySMTPAddress -HiddenFromAddressListsEnabled:$true

}

also if this correct, i need output in .txt file as a result that what this command will do and what changes it will do..
set-adserversettings -viewentireforest:$true
import-csv hide.csv | foreach
{
set-mailcontact -identity $_.PrimarySMTPAddress -HiddenFromAddressListsEnabled:$true
$userchange = $_.PrimarySMTPAddress " hidden from Address List"
}
$userchange | Export-CSV -Path C:\temp\UserChangeLog.csv -NoTypeInformation

Open in new window

is this tested?

what is the line 5 do.. not sure about " hidden from Address List"
Tested:
ForEach ($user in $(Get-Content C:\temp\hide.csv))
{
$change = Set-Mailbox -identity $user -HiddenFromAddressListsEnabled $true
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Andy
Andy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in the command tested, you put Set-mailbox, i think it need to be set-mailcontact..
awsum