Office 365 PowerShell command to display all hidden email objects

Please provide me with an Office 365 PowerShell command or script that will display all items hidden from the email address list (such as mailboxes, contacts, shared items, resources, groups, etc.)
IT GuyNetwork EngineerAsked:
Who is Participating?
 
timgreen7077Exchange EngineerCommented:
I'm assuming you know how to connect to O365 via powershell, so this should help you find the hidden objects in the GAL.

Get-Mailbox -ResultSize unlimited | where {$_.HiddenFromAddressListsEnabled -eq $true} | ft name

Get-MailContact -ResultSize unlimited | where {$_.HiddenFromAddressListsEnabled -eq $true} | ft name
0
 
Vasil Michev (MVP)Commented:
While Tim's solution is technically correct, I would advise to use a server-side filtering instead, as it will be much faster. And also switch to using the Get-Recipient cmdlet, as it covers all applicable objects:

Get-Recipient -Filter {HiddenFromAddressListsEnabled -eq $true}

Open in new window

2
 
IT GuyNetwork EngineerAuthor Commented:
timgreen7077,

I receive these error messages while running the Power Shell commands you provided. I am successfully logged into Office 365 and have tried these commands on two different Office 365 domains.

Please let me know what needs to be done to fix this so I can successfully run these PowerShell commands.

PS C:\Users\Administrator\Desktop> Get-Mailbox -ResultSize unlimited | where {$_.HiddenFromAddressListsEnabled -eq $true
} | ft name
Get-Mailbox : The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Mailbox -ResultSize unlimited | where {$_.HiddenFromAddressListsE ...
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator\Desktop>

------

PS C:\Users\Administrator\Desktop> Get-MailContact -ResultSize unlimited | where {$_.HiddenFromAddressListsEnabled -eq $
true} | ft name
Get-MailContact : The term 'Get-MailContact' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Get-MailContact -ResultSize unlimited | where {$_.HiddenFromAddressLi ...
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-MailContact:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator\Desktop>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
IT GuyNetwork EngineerAuthor Commented:
Vasil Michev (MVP),

I receive this error messages while running the Power Shell command you provided. I am successfully logged into Office 365 and have tried these commands on two different Office 365 domains.

Please let me know what needs to be done to fix this so I can successfully run this PowerShell command.

PS C:\Users\Administrator\Desktop> Get-Recipient -Filter {HiddenFromAddressListsEnabled -eq $true}
Get-Recipient : The term 'Get-Recipient' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Recipient -Filter {HiddenFromAddressListsEnabled -eq $true}
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Recipient:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator\Desktop>
0
 
timgreen7077Exchange EngineerCommented:
get-mailbox and get-mailcontact are valid PowerShell cmdlets for o365. I would suggest verifying that you are actually connected to o365 via PowerShell. You could get this error is you aren't connect completely. I assure you these are valid get commands
0
 
IT GuyNetwork EngineerAuthor Commented:
What are the best steps to take to verify that I am actually connected to Office 365 via PowerShell?

What PowerShell commands can I run to do this?
0
 
timgreen7077Exchange EngineerCommented:
To connect run the following and the credentials is your office 365 logon admin credentials:

$usercredential = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $usercredential -Authentication Basic -AllowRedirection
Import-PSSession $session -allowclobber
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.