Hide, Un-hide, Mailboxes and Block Office365 Users


——-

1.
Open Windows PowerShell

Click Start > All Programs > Accessories > Windows PowerShell

Note: Right-click Windows PowerShell and select Run as administrator. If you get a user account control prompt that
asks if you would like to continue, respond Continue.

2.
Verify PowerShell can run scripts

Run this command:
Get-ExecutionPolicy

Note: If the value returned is anything other than “RemoteSigned”, you need to change the value using Step 3. Otherwise skip to Step 4.

3.
Enable Scrpits to run in PowerShell

Run this command:
Set-ExecutionPolicy RemoteSigned

4.
Connect PowerShell to the cloud-based service

Run the following commands:
$LiveCred = Get-Credential

Note: The above command will open a login window. Enter an Office 365 administrator address and password.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred
-Authentication Basic -AllowRedirection

Import-PSSession $Session

 

1. Hide mailbox users (mailbox enabled) from Global Address Book (GAL) in Office 365
Set-Mailbox -Identity User@domain.com -HiddenFromAddressListsEnabled $true

2. Un-hide mailbox users (mailbox enabled) from Global Address Book (GAL) in Office 365
Set-Mailbox -Identity User@domain.com -HiddenFromAddressListsEnabled $false
$users = import-csv C:\HiddenContacts.csv
Foreach($_ in $users) {Set-mailbox -identity $_.identity -HiddenFromAddressListsEnabled $false}

3. Hide a contact from the Global Address Book (GAL) in Office 365
Set-MailContact emailaddress@mydomain.com -HiddenFromAddressListsEnabled $true

Unhide the contacts from C:\HiddenContacts.csv file by running the following cmdlet
$users = import-csv C:\HiddenContacts.csv
Foreach($_ in $users) {Set-mailcontact $_.identity -HiddenFromAddressListsEnabled $false}

4. Hide all external contacts from the Global Address Book (GAL) in Office 365
Get-MailContact -ResultSize unlimited | Set-MailContact -HiddenFromAddressListsEnabled $true

5. Export a list for contacts hidden from GAL by running the following cmdlet:
Get-Mailcontact -Filter {HiddenFromAddressListsEnabled -eq $true} | Select identity,alias,HiddenFromAddressListsEnabled |
Export-Csv -Path C:\HiddenContacts.csv -NoTypeInformation

6. Block Users (so user will not be able to login to their mailbox)
Set-MsolUser -UserPrincipalName Scott@domain.com -blockcredential $true

Block users from C:\blockusrslist.csv file by running the following cmdlet
$users = import-csv C:\blockusrslist.csv
Foreach($_ in $users) {Set-MsolUser -UserPrincipalName Scott@domain.com -blockcredential $true}

Advertisements

About Robiul

Robiul has 15 years of continuous successful career experience in ICT with extensive background in System Engineering, IT infrastructure design, operations and service delivery, managing IT projects / MIS functions for local and multi-national companies with in-depth knowledge of multiple operating systems as well as construct / manage small to medium size Data Center. Proven ability to design and implement medium to semi-large scale LAN/WAN/WLAN and system infrastructures. Academic qualification: Master of Science in Information Systems. Professional certifications are: MCSE, CCNA, ITIL and FoundStone Security Professional, VCP, NetAPP, CISSP etc.
This entry was posted in Powershell and tagged , , . Bookmark the permalink.