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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.